[Top][All Lists]
[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
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), (continued)
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/01
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Leigh Smith, 2004/02/02
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/02
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Marco Scheurer, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), David Ayers, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool:?), Alexander Malmberg, 2004/02/03
- Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?), Alexander Malmberg, 2004/02/02
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?),
Alexander Malmberg <=
Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/01
Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/01