Subject: Re: NULL return value checking
To: Gary Thorpe <>
From: Greg A. Woods <>
List: tech-kern
Date: 04/24/2002 04:13:00
[ On Tuesday, April 23, 2002 at 18:44:20 (-0400), Gary Thorpe wrote: ]
> Subject: Re: NULL return value checking
> I have always seen NULL defined as 0.

I've seen "(void *)0" in several compilers, but it caused far more
problems than it solved and I've always undef'ed it and reset it to just
plain "0" (zero that is) in my code.....  :-)

> However, NULL simply represents an 
> invalid value for a pointer, and its actually value is PLATFORM SPECIFIC as 
> far as ANSI compliant code goes. That is, a platform can define NULL to be 
> any value which the platform would interprit to be an invalid pointer. NULL 
> is usually zero because the first address in memory is usually never 
> referenced or reserved.

I don't think that's true.  Can you quote chapter and verse on that?  (I
don't have a copy of the ANSI standard...)

> Assuming it is zero is technically incorrect. It *could* be non-zero, in 

I'm pretty sure that's not true.

I do have a copy of the ISO/IEC 9899:1999 document, and it says quite

    An integer constant expression with the value 0, or such an
    expression cast to type (void *), is called a "null pointer
    constant."  If a null pointer constant is converted to a pointer
    type, the resulting pointer, called a "null pointer," is guaranteed
    to compare unequal to a pointer to any object or function.

I.e. no matter how it's defined, NULL == 0.

								Greg A. Woods

+1 416 218-0098;  <>;  <>;  <>
Planix, Inc. <>; VE3TCP; Secrets of the Weird <>