Xref: utzoo comp.std.c:926 comp.lang.c:17208 Checksum: 40127 Lines: 60 Path: utzoo!sq!msb From: msb@sq.com (Mark Brader) Date: Mon, 27-Mar-89 17:40:35 EST Message-ID: <1989Mar27.174035.12843@sq.com> Newsgroups: comp.std.c,comp.lang.c Subject: Re: Testing Equal Pointers (was: detecting invalid pointers) Summary: pANS does say equality means what it says References: <1989Mar21.085704.15894@ateng.ateng.com> <16039@cup.portal.com> <375@sdti.SDTI.COM> Reply-To: msb@sq.com (Mark Brader) Followup-To: comp.lang.c Organization: SoftQuad Inc., Toronto > ... from comp.lang.c ... > > It is possible however to have two pointers point to the same storage > > location but which compare unequal. > > Why is this dismal situation reflected in the pANS? How can standard C > let pointers to the same object compare unequal? ... STANDARD C > PROVIDES NO WAY at all to tell if two pointers point to the same object! Wrong (in pANS, "standard", C), no matter how loud you shout. (I've added a cross-posting back to comp.lang.c to point out that the compiler(s) referred to in the original article would not be complying to the pANS in this respect. Followups are directed to comp.lang.c also, since this article should close the topic from a pANS viewpoint!) The wording here did undergo some late editorial changes and may be different between the October draft and the final December version of the proposed standard. Also, note that the discussion of equality is partly under relational operators, rather than equality operators. This is simply because the presentation (in order of precedence) happens to get to them first. Equality affects the relational operators too because the two expressions a <= b && !(a < b) and a == b are equivalent in the absence of undefined behavior. From Section 3.3.8 "Relational operators", page 50, lines 7-10: # If two pointers to object or incomplete types both point to the same # object, or both point one past the last element of the same array # object, they compare equal. If two pointers to object or incomplete # types compare equal, both point to the same object, or both point # one past the last element of the same array object. There is a footnote about invalid prior operations and undefined behavior. Then, in Section 3.3.9 "Equality operators", page 50, lines 28-36: # [These] operators are analogous to the relational operators except # for their lower precedence. Where the operands have types and values # suitable for the relational operators, the semantics detailed in # Section 3.3.8 apply. # # If two pointers to object or incomplete types are both null pointers, # they compare equal. If two pointers to object or incomplete types # compare equal, they both are null pointers, or both point to the same # object, or both point one past the last element of the same array # object. If two pointers to function types compare equal, either both # are null pointers, or both point to the same function. If two pointers # to function types compare equal, either both are null pointers, or # both point to the same function. There is a footnote which is redundant. Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb@sq.com A standard is established on sure bases, not capriciously but with the surety of something intentional and of a logic controlled by analysis and experiment. ... A standard is necessary for order in human effort. -- Le Corbusier