NULL vs 0
edhall%rand-unix at sri-unix.UUCP
edhall%rand-unix at sri-unix.UUCP
Sat Feb 4 19:32:00 AEST 1984
From: Ed_Hall <edhall at rand-unix>
As I believe has been pointed out here before, the constant `0' has
a special interpretation when assigned or compared to a pointer.
It behaves as the `null pointer' in these cases, *whatever that
happens to be*. Thus, on a given computer a null pointer could
have a non-zero value, and the constant `0' would be interpreted
as that value in a pointer context.
Of course, the place this breaks down is in procedure arguments,
as C currently has no means of declaring whether a given argument
to a procedure call is a pointer or not. This would then require
a cast to produce the correct null-pointer value.
Another solution is to have the compiler produce code which checks
each pointer parameter for zero and converts it to the proper null-
pointer value before it is used inside the called procedure.
Compiler writers have been forced to do worse things by unusual (to
C) architectures. This should work except when an actual zero is a
legal (and non-null) pointer. (This, by the way, would be possible
on a split I/D PDP-11 if the loader didn't start the data segment at
an address of 2; I'm certain loaders for other machines could be
hacked if necessary to make zero unique.)
-Ed Hall
Rand Corporation
Santa Monica, CA
edhall at rand-unix (ARPA
decvax!randvax!edhall (UUCP)
More information about the Comp.unix.wizards
mailing list