gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?)


From: Alexander Malmberg
Subject: Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?)
Date: Mon, 02 Feb 2004 17:58:01 +0100

Leigh Smith wrote:
> > Hm, well, actually I do prefer "if (ptr == NULL)" over "if (!ptr)".
> > Not sure why.
> 
> Implicit is the assumption that NULL is always 0, which isn't actually
> a specification, merely a convention of the compiler that NULL is
> actually something like:
> 
> #define NULL (void *) 0

This is incorrect (and something of a myth). 0 is _always_ the null
pointer. NULL is just an alias for it. See
http://www.eskimo.com/~scs/C-faq/s5.html (which also has references to
the relevant parts of the spec).

> While unusual for a compiler to declare NULL to be something other than
> 0, it would be legal C,

No, it wouldn't.

> depending on the processor architecture.

On architectures where null pointers aren't represented with all bits 0,
0 in the source is _still_ always the null pointer. It is the compiler's
responsibility to convert those zeroes (explicit, or implicit in
comparisons like "if (ptr)") to whatever the architecture needs.

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]