🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #798

Re: Two questions about pointers

#798
From: Doug Gwyn
Date: Fri, 20 Oct 1989 13:49
31 lines
1835 bytes
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.
Technical Details
Message-ID: <11352@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!haven!adm!smoke!gwyn
References: <1989Oct18.121516.10695@anucsd.oz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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