What C compilers have non-zero null pointers?

John Chambers jc at minya.UUCP
Mon Jul 9 00:14:25 AEST 1990


After following a bit of debate in another newsgroup concerning 
dereferencing null pointers, I've become curious as to how various
C compilers actually represent null pointers.  I've never actually
seen a C compiler that uses anything other than all 0 bits for
a null pointer, but some people insist that this is quite common
(and I'm a total idiot for not knowing it ;-).  Now, I've known
for some time that all-zeroes wasn't the *required* representation
of a null pointer, but I also understand why it's the obvious one.
Consider that the C bible (page 192) says, concerning assignments
to/from pointers and other types, "The assignment is a pure copy
operation, with no conversion."  This means that in:
	int i;
	char*p;
	i = 0;
	p = i;
the value assigned to p is the same bit pattern as i (which needs
to be long on some machines, of course).  Now, I've never even
heard of a C compiler that uses anything other than all zeroes
for an int (or long) 0, so it seems to my naive little mind that
p must be all zeroes, also.  Of course, the manual doesn't quite
say anywhere that the above code gives p the same value as 
	p = 0;
though I sorta expect that most programmers would be surprised
if the values were different.

Anyhow, what's the story here?  Are there really C compilers that
use something other than all-zero bits for a null pointer?  If so,
can you name the compilers, and describe their representations and
how they handle code like the above?

This seems like it could be the source of a lot of fun portability
problems.  Any insights here?

[It seems to me that it'd be useful if there were a compiler option
to specify the representation of null pointers, but that's probably
far too much to hope for... :-]

-- 
Typos and silly ideas Copyright (C) 1990 by:
Uucp: ...!{harvard.edu,ima.com,eddie.mit.edu,ora.com}!minya!jc (John Chambers)
Home: 1-617-484-6393
Work: 1-508-952-3274



More information about the Comp.lang.c mailing list