how has C bitten you? (Really,

lee at eel.UUCP lee at eel.UUCP
Thu Aug 29 11:52:00 AEST 1985


>>Gee....and I thought a zero pointer was guaranteed not to point to
>>anything valid (K&R says this).

>All valid implementations of C guarantee this.  Obviously, the
>implementation of C that this was done on is not valid.  He should complain
>to the vendor.  (Yes, there have been such implementations; one well-known
>chip maker's first UNIX release didn't put the necessary shim at data
>location 0 on a separate I&D space program.  They fixed it shortly
>afterwards.)

Speaking of issues that have been beaten to death!  K&R says only that the
value 0 is distinguishable from pointers that point to objects, and that
therefore the value zero is not a "valid" pointer.  It certainly does not
say that the 0 pointer will give you the "null" or empty value of any
object, and in particular it does not promise that there will be an integer
zero if you dereference (int*)0, or a character zero if you dereference
(char*)0, nor a memory fault if you reference (foo*)0.

NO, you cannot depend upon the value obtained by dereferencing ANY pointer
that has been assigned the value zero.  It does not point to any object;
the implementation of C does not guarantee  to protect you from erroneously
trying to access that object and the result is unpredictable over various
implementations.



More information about the Comp.lang.c mailing list