是空指针在Objective-C未定义行为? [英] Is null pointer dereference undefined behavior in Objective-C?

查看:166
本文介绍了是空指针在Objective-C未定义行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C和C ++中,空指针引用是未定义的行为。有关Objective-C的什么?

In C and C++, null pointer dereference is undefined behavior. What about Objective-C?

在换句话说,这是什么code保障办?

In other words, what is this code guaranteed to do?

*(long*)0 = 0;

背景:不知这个答案可能会引发未定义的行为可能造成类似的声明随机的东西被优化掉了,甚至怪异的事情。

Background: I wonder if this answer might trigger undefined behavior potentially causing random things like the statement being optimized out or even weirder things.

当然,我并不赞同这样做。仍然,重要的是要知道的语言的规则。

Of course, I do not endorse doing this. Still, it is important to know the rules of the language.

推荐答案

由于Objective-C的无非是基于C之上的面向对象层以上,纯C语句没有特殊的附加意义。根据这一点,在这种情况下, *(长*)= 0; 评估和帧间$ P $用C PTED就像(因为它的的C),因此它调用未定义的行为。因此,它不能保证做任何事情。

Since Objective-C is nothing more than an object-oriented layer on top of C, pure C statements don't have special additional meanings. According to this, in this case, *(long*)0 = 0; is evaluated and interpreted just like in C (since it is C) and thus it invokes undefined behavior. As such, it is not guaranteed to do anything.

这篇关于是空指针在Objective-C未定义行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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