[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 18:47:11 +0100 |
Helge Hess wrote:
[snip]
> Good point! Just checked the C99 draft:
> http://www.vmunix.com/~gabor/c/draft.html#7.1.6
>
> which indeed proves you right :-) NULL is not required to be defined as
> 0.
This is true, but misleading. The quote from the spec (7.17) reads:
""
... NULL which expands to an implementation defined null pointer
constant; ...
""
and for "null pointer constant" we have (6.3.2.3, or 6.2.2.3 in the
draft in that link; wording seems identical):
""
3 An integer constant expression with the value 0, or such an
expression cast to type void *, is called a null pointer constant. ..."
""
While NULL does not have to be defined as plain "0", it does have to be
defined as a null pointer constant, and that's essentially the same
thing as a plain "0" (since "0" is a null pointer constant, and "Any two
null pointers shall compare equal." (6.3.2.3, 4)).
Thus, an implementation could choose to do:
#define NULL (1-1)
and still be correct. :) In practice, it means that implementations can
do:
#define ((void *)0)
instead of just "0".
> On the other side - a ptr used in a boolean expression might be
> specified to test against "!= NULL" - not sure, need to read that up,
> but would make sense and sounds likely.
I don't know if it's summed up anywhere, but at least it's specified at
each place where it matters. Thus, for "if" ""compares unequal to 0""
(6.8.4.1), for "for","while","do" ""compares equal to 0"" (6.8.5), for
"_Bool" ""compares equal to 0"" (6.3.1.2), etc.. (In the linked draft,
just search for "equal to 0".) 0 is a null pointer constant, so "if
(ptr)" is correct.
- Alexander Malmberg
- Re: Re[2]: [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: ?), 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 <=
- 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, 2004/02/02
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