What C compilers have non-zero null pointers?

D'Arcy J.M. Cain darcy at druid.uucp
Tue Jul 17 22:36:27 AEST 1990


In article <9007161750.AA00664 at edison.CHO.GE.COM> rja <rja at edison.cho.ge.com> writes:
>I used to use a compiler for MSDOS and the 80x86 cpus 
>whose NULL pointer was F000:0000 hex when examined via
>a debugger.  It of course did compile fine as long as one
>used sense and compared pointers to NULL rather than 
>a constant of zero...
>
Which compiler was that?  I hope it didn't claim to be ANSI compatible.  The
NULL pointer does not have to be represented in memory as all zero bits but
it does have to be represented by the string "0" in the context of a pointer
comparison.  Comparing a pointer to 0 is always correct and does not have
anything to do with the internal representation of the NULL pointer.

However I always use NULL for two reasons.  Broken compilers on brain dead
CPUs and if NULL is defined as "(void *)0" then it tests for accidentally
testing a NULL pointer against a non pointer variable.  For example:
    int a = 0;
    if (a == NULL)
        do(something);
If tested against 0 the compiler won't complain but it will complain if it
is tested against (void *)0.  At least GNU C complains.  In other words, use
NULL not because 0 may not be the NULL pointer but because NULL can't be
anything else.

-- 
D'Arcy J.M. Cain (darcy at druid)     |   Government:
D'Arcy Cain Consulting             |   Organized crime with an attitude
West Hill, Ontario, Canada         |
(416) 281-6094                     |



More information about the Comp.lang.c mailing list