see http://www.eskimo.com/~scs/C-faq/s5.html
for info on the NULL pointer.

summary of this:
5.1 there is a special value--the ``null pointer''--which is
distinguishable from all other pointer values and which is
``guaranteed to compare unequal to a pointer to any object or function.''
5.2 ``0'' in a pointer context is converted into a null pointer at compile
time.
5.3 if(p)   is equivalent to        if(p != 0)
5.4 the preprocessor macro NULL is #defined (by
<stdio.h> or <stddef.h>) with the value 0, possibly cast to (void *)
5.5 it is the compiler's responsibility to generate whatever bit pattern
the machine uses for
that null pointer. Therefore, #defining NULL as 0 on a machine for which
internal null pointers are nonzero is as valid as on any other
5.6 there are machines which use different internal representations for
pointers to different types of data
5.9 If NULL and 0 are equivalent as null pointer constants, which should I
use? ... There is no one right answer. ... NULL should not be used when
another kind of 0 is required, ... do not use NULL when the ASCII null
character (NUL) is desired.
5.10 NULL is used only as a stylistic convention
...
5.14 The construct ``if(p == 0)'' is easily misread as calling for
conversion of p to an integral type, rather than 0 to a pointer
type, before the comparison
...

I hope this helps clear this one up a bit...

Pete (Confused yet? :)

On Wed, 27 May 1998, Andrea Arcangeli wrote:

> On Thu, 28 May 1998, Pete Ryland wrote:
> 
> >ok - this is often confused.  the c faq has a *big* section on this...
> >
> >NULL should be defined as 0.
> 
> Ok.
> 
> >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
> 
> This sound me a little strange. I think that if I use (void *)0 the
> compiler must use 0 not -1. If ANSI-C declare that a NULL pointer is a
> (void *)0 is another story. I' d like if somebody could confirm that I am
> wrong. 
> 
> >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.
> 
> Ok, I understood this and this is not more an issue at least for me.
> 
> 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