What C compilers have non-zero null pointers?

brian scearce bls at svl.cdc.com
Sat Jul 14 05:01:30 AEST 1990


The CDC Cyber series of computers uses not-all-0-bits for NULL.
Cyber addresses are 48 bits long, with 4 bits for ring, 12 bits
for segment and 32 bits for offset.  If you load an address register
with a number with ring == 0, you get a hardware trap.

So, on our compiler, NULL is represented by ring == (ring your
program is executing in), segment == 0, offset == 0.

This means that you have to be quite careful in those situations
where you type 0 and mean NULL and it isn't inferable from context
what you mean.  The only time that this makes a difference is (I
think) arguments to functions (should be "non-prototyped functions",
but I haven't implemented ANSI yet).

So, the output from:
main()
{
  char *p = 0;
  printf("%x\n", (int)p);
}

is:
b00000000000

Its still a very good compiler.  Really.  This small oddity isn't
as bad as most people seem to think.  As I've explained to a few
through email, it's almost like floating point.  Nobody expects
2.0 to have the same representation as 2, but we still write 2
sometimes when we mean 2.0 (like double x = 2; is OK).  

--
Brian Scearce        \ "I tell you Wellington is a bad general, the English are
(not on CDCs behalf)  \ bad soldiers; we will settle the matter by lunch time."
bls at u02.svl.cdc.com    \   -- Napolean Bonaparte, June 18, 1815 (at Waterloo)
shamash.cdc.com!u02!bls \ From _The Experts Speak_, Cerf & Navasky



More information about the Comp.lang.c mailing list