Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: Two questions about pointers Message-ID: <11352@smoke.BRL.MIL> Date: 20 Oct 89 13:49:29 GMT References: <1989Oct18.121516.10695@anucsd.oz> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 31 In article <1989Oct18.121516.10695@anucsd.oz> bdm@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? A correct statement would be: Two pointers that are constructed by following the rules in the Standard, and for which the Standard says they point to the same object, are indeed required to compare equal. If you construct your pointers-to-the-same-object by sneaky means for which the Standard makes no such guarantee, then they may compare unequal. Of course, in MOST implementations they would compare equal in any case, but not in ALL implementations. >(2) If two pointers of the same type compare equal, and each is cast >to a second pointer type, must the results compare equal? Again, if you have not stepped beyond the bound of what the Standard guarantees, then the resulting pointers will also compare equal. There are certain constraints that are required to be observed; for example, alignments must be suitable. >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. The implementations don't have to be especially weird. Some implementations are in fact expected to have to perform an explict "normalizing" operation before testing for pointer equality.