Creating pointer with all bits 0 (was: Referencing NULL pointers)

Jeffrey Kegler jeffrey at algor2.algorists.com
Sun Sep 10 14:00:55 AEST 1989


Guy Harris writes:

> 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."

> Well, it might be fixable in the interpretation phase, since 3.1.2.4
> has this to say ... and 4.10.3 has this to say ... while 3.3.4 says
> only ... and 3.1.2.5 says ...  so I see no obvious indication here
> that the result of converting an arbitrary integer to a pointer is a
> pointer whose value refers to an *object* 

The definition of 1.6 is loose enough that any readable physical
location is an "object".  In fact, the "readable" may not even be a
requirement.

1.6 defines an object as "a region of data storage in the execution
environment, the contents of which can represent values."  Given the
target might be firmware it is clear that the definition has to be
this broad.  There is no reference to declaration or C language in the
definition of "object", nor should there be.

Note this means Doug Gwyn's workaround (having a dummy for the null
pointer to point to, if worst comes to worst) to 3.2.2.3, while it
will achieve the intent of the standard, still violates its exact
wording as quoted above.

> it seems only to refer to an "entity".  The only way I see of
> getting an object is to define it with static or automatic storage
> duration, or call "malloc" or "calloc".

As above, objects can pre-exist, and be accessed with the result of an
integer to pointer cast.  This appears to have been explicitly the
intention (Footnote 42).

> It's perhaps not ideal that the definition of "object" doesn't
> explicitly indicate how you get objects, but I think this may be, as
> indicated, repairable in the interpretation phase, if necessary.

Can sections of the standard be rewritten in the "interpretation
phase"?  It seems this might be what it amounts to.

[ Aside: In this context 3.1.2.4 reads very strangely.  It says every
object has one of two storage durations (static and automatic).  It
goes on to say that the storage duration depends on the declaration,
apparently assuming every object has one, which of course is not the
case. ]
-- 

Jeffrey Kegler, Independent UNIX Consultant, Algorists, Inc.
jeffrey at algor2.ALGORISTS.COM or uunet!algor2!jeffrey
1762 Wainwright DR, Reston VA 22090



More information about the Comp.lang.c mailing list