Rust runtime error: Illegal instruction: 4

use std::intrinsics;
#[deriving(Show)]
struct NewType<‘a, T: ‘a> {
    a:int,
    b:String,
    v: &‘a T
}
fn main() {
        let t: NewType<int> = unsafe{ intrinsics::init()};
        println!("{}", t); // Error at this line
}
$ rustc mem.rs
$ ./mem
Illegal instruction: 4

why?

答案:

11:33 < Dragon> hello, I got a runtime error: Illegal instruction: 4, can any one help me out? code

snipet at http://my.oschina.net/zengsai/blog/360320

11:33  * Twisol shuffles over to the corner.

11:33 < Dragon> based on latest rustc

11:34 -!- chingucha [[email protected]] has quit [Ping timeout: 121 seconds]

11:34 < FreeFull> Dragon: That‘s because you‘re creating a null pointer dereference

11:35 < Dragon> FreeFull: how?

11:35 < FreeFull> When it‘s trying to print out the v field, specifically

11:35 < Twisol> Dragon: `unsafe{ intrinsics::init()}`

11:36 -!- nucleartide [[email protected]] has quit [Ping timeout: 121 seconds]

11:36 < FreeFull> References are meant to be never null, but you created a null reference with that

unsafe block, and tried to print it out

11:36 -!- chingucha [[email protected]] has joined #rust

11:36 < FreeFull> Printing a reference prints the data behind it

11:36 < Twisol> Dragon: `intrinsics::init()` creates a value initialized with all zeroes. Your data

has a pointer in it, so that pointer gets set to 0.

11:36 < meh> shouldn‘t it segfault tho?

11:37 < Dragon> ok, i see , thanks FreeFull Twisol

时间: 2024-10-14 09:13:19

Rust runtime error: Illegal instruction: 4的相关文章

win7,M?i?n?d?m?a?n?a?g?e?r?2?0?1?2使用模板时弹出Runtime error R6025解决方法

Mindjet.MindManager2012.v10.0在应用个别模板时提示"参数错误",然后自动关闭. 解决办法: 如果是win7系统,可以进入C:\Users\(用户名)\AppData\Local\Mindjet\MindManager\10\Library\ENU\Templates, 可以看到如下模板:Management/Meetings and Events/Personal Productivity/Problem Solving/Project Management

C Run-Time Error R6034问题的解决

1.问题描述 这两天一直在用vs2008编写一个小项目,需要在c++代码中通过命令行的方式调用cl.exe和link.exe,也就是给编译器cl和链接器link传递参数,然后编译链接生成可执行文件exe.最终生成的result.exe运行时老出现Runtime Error R6034 An application has made an attempt to load the C runtime library incorrectly.的错误,围绕这个问题,我查了两天的资料,最后终于解决了..

error error: illegal character: &#39;\u3000&#39;

写leetcode 一直是 error: illegal character: '\u3000' '\u3000' 我就奇怪这到底是个啥! 中文(全角)空格!!! 什么鬼口亨 error error: illegal character: '\u3000'

Runtime Error

啊啊啊,最近好多Runtime Error,心塞. runtime  error (运行时错误)就是程序运行到一半,程序就崩溃了. 比如说: ①除以零 ②数组越界:int a[3]; a[10000000]=10; ③指针越界:int * p; p=(int *)malloc(5 * sizeof(int)); *(p+1000000)=10; ④使用已经释放的空间:int * p; p=(int *)malloc(5 * sizeof(int));free(p); *p=10; ⑤数组开得太大

mindmanager2012打开文件出现runtime error r6025 解决方案

关于mindmanager 2012启动无法运行,提示c++错误 ---------------------------Microsoft Visual C++ Runtime Library---------------------------Runtime Error! Program: D:\Program Files\Mindjet\MindManager 10\MindManager.exe abnormal program termination ------------------

[Nuget] - &quot;Runtime error: Could not load file or assembly &#39;System.Web.WebPages.Razor, Version=3.0.0.0&#39;&quot; 问题之解决

环境 项目中使用了 System.Web.WebPages.Razor, Version=3.0.0.0,Nuget 还原缺失包后自动更新至 Version=3.2.5.0,编译成功,运行失败. 错误 "/"应用程序中的服务器错误.未能加载文件或程序集"System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"或它的某一个依赖项.系统找不到

Microsoft Visual C++ Runtime Library Runtime Error的解决的方法

打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. 有些时候,在你安装.执行某个软件,可能会得到这样一个错误提示: Microsoft Visual C++ Runtime Library Runtime Error! Program:c:/windows/explorer.exe This application has requested the

runtime error 的原因

1.   括号 做题时偶然发现的! (详见 else if( arefriends(x,y)==-1 ) 4.  死循环  刚刚又发现一个,真“倒霉”,都让我碰见了 (详见  POJ 2236 Wireless Network)   if(x!=y)//--------此处这个判断千万不能少,否则出现死循环,提交会出现runtime errorset[x]=y; 这道题 是 树 的并查集 的 题目, 由于 这里 的 set [ ] 数组  保存 父节点,如果 不加 判断条件 的话 , 那么 就是

ArcGIS10.4 Runtime Error R6034

现在甲方采购的ArcGIS Desktop正版,一般都是较高的版本(10.4或10.4.1),但10.4经常报出C++ Runtime R6034错误. 问题 "Microsoft Visual C++ Runtime Library" Runtime Error! Program: C... R6034 An application has made an attempt to load the C runtime library incorrectly. Please contac