NULL question not in FAQ

Phil Howard KA9WGN phil at ux1.cso.uiuc.edu
Wed Mar 27 09:56:43 AEST 1991


Given that the compiler is supposed to translate the constant "0" to the
appropriate value for a NULL pointer on the machine type, how does one
get a pointer value whose representation happens to be all zeroes, but
is a non-NULL pointer?

Are all of these equivalent or are any differnt?

    p = ( (char *) 0 );
    p = ( (char *) 00 );
    p = ( (char *) 0x0 );
    p = ( (char *) 0x00 );
    p = ( (char *) 1-1 );

If not, what are they supposed to compile to?

Suppose I do this:

    char *p;
    int i;
    p = NULL;
    i = (int) p;

Will I get a value of zero in "i" always, regardless of the way the
machine type represents a NULL?

I am wanting to discern whether or not the special case of a pointer value
being translated to the NULL representation is done with the particular
constant of a single digit "0" or if it is done with ANY constant whose
integer value is numerically 0.

For low level code, e.g. drivers and such, where portability and machine
independence are not issues, it would still be nice to be able to cast
address values into pointers as desired.  Some machine types might very
well have special functionality at address 0x00000000 and uses some other
form of address for a NULL.  Some machine types actually have no NULL at
all and one is simply chosen by convention.

Can someone summarize this, depending one what the real answers are, and
include it in the FAQ in the section on NULL?  This might clear up (or
confuse further) the distinction of NULL.
-- 
 /***************************************************************************\
/ Phil Howard -- KA9WGN -- phil at ux1.cso.uiuc.edu                              \
\ Lietuva laisva -- Brivu Latviju -- Eesti vabaks                             /
 \***************************************************************************/



More information about the Comp.lang.c mailing list