gnustep-dev
[Top][All Lists]
Advanced

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

Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBo


From: Helge Hess
Subject: Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?)
Date: Mon, 2 Feb 2004 12:00:29 +0100

On Feb 2, 2004, at 6:01 AM, 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

While unusual for a compiler to declare NULL to be something other than 0, it would be legal C, depending on the processor architecture. I'd definitely favour the more explicit ptr == NULL since you are then articulating that you are checking against a NULL pointer, rather than doing an implicit cast to an integer before then inverting the implicit comparison against 0.

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.

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.

Greets
  Helge
--
OpenGroupware.org => http://www.opengroupware.org/





reply via email to

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