Re: !foo vs foo == nil
Re: !foo vs foo == nil
- Subject: Re: !foo vs foo == nil
- From: "mm w" <email@hidden>
- Date: Wed, 20 Aug 2008 17:07:17 -0700
as Mike and me pointed NULL === NULL
but Im yet not alright with
(!foo) === if(foo == nil)
as I sent previously
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *p1;
char *p2 = NULL;
free(p1);
free(p2);
return 0;
}
On Wed, Aug 20, 2008 at 4:57 PM, Michael Ash <email@hidden> wrote:
> On Wed, Aug 20, 2008 at 7:15 PM, Torsten Curdt <email@hidden> wrote:
>> I guess my questions wasn't phrased correctly. The point was more: is 'nil'
>> really the equivalent of 0 or NULL.
>>
>> There was a common perception that NULL is not really the same as nil. But
>> seems like in the end it really is (void*)0.
>
> As always, it's helpful to follow the rabbit down his hole and see
> where he goes.
>
> On stddef:403 we find this:
>
> #define NULL ((void *)0)
>
> So that's what NULL really is, at least on my system. Now, on
> objc/objc.h:57 we find this:
>
> #define nil __DARWIN_NULL /* id of Nil instance */
>
> Well, we have to follow that a bit further. But here we are, on sys/_types.h:91:
>
> #define __DARWIN_NULL ((void *)0)
>
> So not only are NULL and nil equivalent, they are the *same thing*.
>
> (Now, they don't have to be. As I recall, NULL can just be a plain
> integer 0 as well. But they do have to be equivalent, and it just so
> happens that they are identical even though they don't need to be.)
>
> Now, that's not to say that they're semantically equivalent. NULL is
> meant to be any pointer type, whereas nil is meant to be for objects
> only (and Nil, capital N, is meant to be for the Class type). So it's
> best to keep that separation in your code to better indicate what's
> truly going on. After all, that's why nil (and Nil) exist at all,
> rather than just reusing NULL. But in the end they are ultimately the
> same.
>
> Mike
> _______________________________________________
>
> 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
>
--
-mmw
_______________________________________________
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