Two questions about pointers

T. William Wells bill at twwells.com
Sat Oct 21 10:51:45 AEST 1989


In article <1989Oct18.121516.10695 at anucsd.oz> bdm at anucsd.oz (Brendan McKay) writes:
: (1) Is it true that two pointers of the same type which point to the
: same object must compare equal?

Yes. See 3.3.9. Read further before disagreeing.

: (2) If two pointers of the same type compare equal, and each is cast
: to a second pointer type, must the results compare equal?

If there is an object there of that new type, yes. (E.g., unions.)
Or, if both pointers were originally of the new type, yes.

As near as I can tell, converting two pointers to a void* and then
testing for equality does not have to work, unless both were
void*'s to begin with.

: 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*.

You either have an old draft or you have not read yours carefully.
>From the May 88 draft: "If two pointers point to the same object
or function, they compare equal."

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com



More information about the Comp.std.c mailing list