Re: !foo vs foo == nil
Re: !foo vs foo == nil
- Subject: Re: !foo vs foo == nil
- From: Ken Thomases <email@hidden>
- Date: Wed, 20 Aug 2008 19:47:39 -0500
On Aug 20, 2008, at 7:43 PM, Torsten Curdt wrote:
On Aug 21, 2008, at 01:50, Ken Thomases wrote:
On Aug 20, 2008, at 6:15 PM, Torsten Curdt wrote:
I guess my questions wasn't phrased correctly. The point was more:
is 'nil' really the equivalent of 0 or NULL.
Let's put it this way: freshly allocated objects have their memory
zeroed out,
Why should that affect the pointer to an object?
If you make a class with ivars which are object pointers, you are
guaranteed by the runtime that they are zeroed out, which is to say
nil, when an instance is allocated. I was pointing out that the
runtime equates zeroing out the object's memory with guaranteeing that
its object-pointer ivars are nil.
From <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_6.html#//apple_ref/doc/uid/TP40002974-CH4-DontLinkElementID_86
>:
An allocation message does other important things besides allocating
memory:
[...]
It initializes all other instance variables to zero (or to the
equivalent type for zero, such as nil, NULL, and 0.0).
Right there is a guarantee that nil equals zero.
Cheers,
Ken
_______________________________________________
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