ok - this is often confused.  the c faq has a *big* section on this...

NULL should be defined as 0.
0 cast to a pointer type is defined as an undefined pointer and can be
implemented by the compiler as any number (including -1, or something
that will be assured to cause a tlb/pagetable miss).  Therefore, both the
compare with zero and the straight "!" usage and the compare with NULL
will give the same results on any system that is ANSI-C.  There are no
problems with portability, even on systems that have non-zero null 
pointers.

(Note that it has been a while since I've gone through the C faq, so I
could well be wrong... :)

Pete

On Wed, 27 May 1998, Andrea Arcangeli wrote:

> On Wed, 27 May 1998, Glynn Clements wrote:
> 
> >
> >Andrea Arcangeli wrote:
> >
> >> > But for testing null pointers, I use `!'. In this context, it seems
> >> 
> >> BAD. I worked in envinronments where NULL is ((void *)-1UL).
> >
> >That's _really bad_. ANSI C requires stdio.h to define NULL as being
> >equivalent to zero.
> 
> Hmm, this is true in user land. Is it still true in kernel (not Linux)
> developement?
> 
> >> If you use ! to check for a NULL pointer you make your code not
> >> portable.
> >
> >Using ! to check for a NULL pointer is entirely portable.
> 
> If so excuse me, but for safe I will continue to use == NULL instead of !
> ;-).
> 
> Andrea[s] Arcangeli
> 

Pete Ryland     Home phone: +61 2 9697 9262     Mobile: 014 035 802
email: [EMAIL PROTECTED]  ICQ UIN: 4256333
WWW: http://www.pdr.ml.org      ftp: ftp.pdr.ml.org

Reply via email to