Creating pointer with all bits 0

Alan J Rosenthal flaps at dgp.toronto.edu
Thu Sep 7 02:52:03 AEST 1989


Really, an implementation is free to accept "*(char *)0 = 5;" as an instruction
to set memory location zero to 5.  Dereferencing a null pointer gets undefined
behaviour.  This is a non-problem.


jeffrey at algor2.algorists.com (Jeffrey Kegler) writes:
>Question: Is an implementation whose null pointer is the same as the
>result of some integer-to-pointer cast conforming?  Apparently not,
>since 3.2.2.3 states, "... a null pointer is guaranteed to compare
>unequal to a pointer to any object or function."

I think the contents of a special memory location is not necessarily an
"object" in the pANS sense.  In any case, dereferencing the null pointer
is an implementation-specific way of accessing this memory location, and
need not be construed as a normal pointer dereference (although it would
probably be implemented as such).  For example, the (FILE *)0 argument to
fclose() to close all fps is not a pointer to an object, although if only
one file is open it does refer to an object.

ajr



More information about the Comp.lang.c mailing list