Two questions about pointers

Brendan McKay bdm at anucsd.oz
Wed Oct 18 22:15:16 AEST 1989


Here are two questions about the semantics of pointers, as defined by
the proposed ANSI standard.
 
(1) Is it true that two pointers of the same type which point to the
same object must compare equal?
 
(2) If two pointers of the same type compare equal, and each is cast
to a second pointer type, must the results compare equal?
 
The answer to both questions is "yes" in all implementations I can think of,
and will probably be "yes" in any implementation in which pointers are
represented just as machine addresses without meta-information.
 
The question is whether the proposed standard actually requires such
behaviour.  One can design weird pointer implementations which obey all the
rules relating to pointers, as far as I can see, but which do not have one
or both of these properties.  I can e-mail an example to anyone interested.
 
Note that Section 3.3.9 does not answer Question (1), at least not directly.
It gives the implication around the other way (equal pointers must point to 
the same object).  Question (2) is of particular interest if the second 
type is void*.
 
If I am correct in thinking that these properties are not required by the
standard, was that intentional, or was it an oversight?
If I'm not correct, please be gentle.
 
Brendan McKay,    bdm at anucsd.oz  or  bdm at anucsd.oz.au



More information about the Comp.std.c mailing list