这是什么说法*的功能(长*)= 0;? [英] What is the function of this statement *(long*)0=0;?

查看:100
本文介绍了这是什么说法*的功能(长*)= 0;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下code, *(长*)= 0; 与一起使用如果条款,但其目的是什么?

 如果(r.wid * r.ht< TOT)
    *(*长)= 0;


解决方案

它写PTED为地址0 0间$ P $一个,即 NULL 指针。这不是一个有效的事情在做,因为 NULL 是从来没有在你可以有效有你的程序可以访问数据的地址。这code触发器的未定义行为的;你不能依赖它有什么特别的效果一般。

然而,往往code像这样被用于强制分段故障型死机,有时方便的拖放到一个调试器。

再次,这是的未定义行为的;也不能保证它会引起这种故障,但有段错误的系统中,上述code是pretty可能生成一个。在其它系统上它可能做一些完全不同的。

如果的你得到一个段错误,它有时更方便触发单这种方式比通过手动设置在调试器断点。例如,如果你不使用IDE,它往往更容易在所需的地方键入那几个标记到code,比它是给(文本)命令来调试程序,指定确切来源code文件和行号手动可以是一个有点讨厌。

In the following code, *(long*)0=0; is used along with the if clause, but what is its purpose?

if(r.wid*r.ht < tot)
    *(long*)0=0;

解决方案

It writes 0 to 0 interpreted as the address of a long, i.e. the NULL pointer. It's not a valid thing to be doing, since NULL is never an address at which you can validly have data that your program can access. This code triggers undefined behavior; you cannot rely on it to have any particular effect, in general.

However, often code like this is used to force a segmentation fault-type crash, which is sometimes handy to drop into a debugger.

Again, this is undefined behavior; there is no guarantee that it will cause such a fault, but on systems that have segmentation faults, the above code is pretty likely to generate one. On other systems it might do something completely different.

If you get a segfault, it's sometimes more convenient to trigger one this way than by manually setting a breakpoint in the debugger. For instance if you're not using an IDE, it's often easier to type those few tokens into the code in the desired place, than it is to give the (textual) command to the debugger, specifying the exact source code file and line number manually can be a bit annoying.

这篇关于这是什么说法*的功能(长*)= 0;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆