In C and C++, null pointer dereference is undefined behavior. What about Objective-C?
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.
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.