What C compilers have non-zero null pointers?
Henry Spencer
henry at zoo.toronto.edu
Wed Jul 11 01:59:41 AEST 1990
In article <422 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
>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...
Reading the Old Testament (K&R1) and trying to apply it to modern C is
a mistake. This code isn't even legal nowadays. You need an explicit
cast to turn the int into a pointer, and there is no promise that that
cast doesn't do some sort of arcane conversion operation.
Actually, even the Old Testament continued with: "This usage is
nonportable, and may produce pointers which cause addressing exceptions
when used. However, it is guaranteed that assignment of the *constant*
0 to a pointer will produce a null pointer distinguishable from a
pointer to any object." [emphasis added]
The constant 0 in a pointer context has no relationship whatsoever to
the integer value 0; it is a funny way of asking for the null pointer,
which need not resemble the int value 0 in any way.
--
NFS is a wonderful advance: a Unix | Henry Spencer at U of Toronto Zoology
filesystem with MSDOS semantics. :-( | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list