Creating pointer with all bits 0 (was: Referencing NULL pointers)
Guy Harris
guy at auspex.auspex.com
Sun Sep 10 06:40:22 AEST 1989
>>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."
>
>This looks like a bit of a problem all right. Can it still be fixed
>by editorial change? For example, "... any legally created object or
>function" or "... any C object or function."
Well, it might be fixable in the interpretation phase, since "3.1.2.4
Storage durations of objects" has this to say:
An object has a *storage duration* that determines its
lifetime. There are two storage durations: static and
automatic.
An object whose identifier is declared with external or
internal linkage, or with the storage-class specifier "static"
has *static storage duration*. ...
An object whose identifier is declared with no linkage and
without the storage-class specifier "static" has *automatic
storage duration*. ...
and "4.10.3 Memory management functions" has this to say:
...
The "calloc" function allocates space for an array of "nmemb"
objects, each of whose size is "size". ...
...
The "malloc" function allocates space for an object whose
size is specified by "size" ...
while "3.3.4 Cast operators" says only:
...
An arbitrary integer may be converted to a pointer. The result
is implementation-defined.
...
and "3.1.2.5 Types" says:
...A pointer type describes an object whose value provides a
reference to an entity of the referenced type. ...
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* - 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".
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.
More information about the Comp.lang.c
mailing list