Re: [Obj-C] if (self) vs. if (self != nil)
Re: [Obj-C] if (self) vs. if (self != nil)
- Subject: Re: [Obj-C] if (self) vs. if (self != nil)
- From: Marco S Hyman <email@hidden>
- Date: Fri, 24 Feb 2012 13:50:55 -0800
>> I also heard that generally speaking NULL is not necessarily always
>> equal to 0 on all architectures.
>
>
> I don't believe this is the case. There can be funny issues with BOOL types, such that BOOL == YES is an inadvisable construct, since your BOOL could be an integer of any value.
In the C language an integral constant expression with the value 0 will always
translate to a null pointer. The actual representation of a null pointer in
memory may not be 0. Different pointer types may have different internal
values. The compiler will know how to translate "0" to the appropriate value
IF it knows the value is being used as a pointer.
See http://c-faq.com/null/index.html for lots more on the subject. It explains
thing like why func(x, 0) may not generate the same code as func(x, (char*) 0).
Marc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden