Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!columbia!rutgers!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Distinguished pointers (was Re: Weird syscall returns) Message-ID: <25045@sun.uucp> Date: Thu, 6-Aug-87 14:37:39 EDT Article-I.D.: sun.25045 Posted: Thu Aug 6 14:37:39 1987 Date-Received: Sat, 8-Aug-87 12:00:06 EDT References: <1158@copper.TEK.COM> <8317@utzoo.UUCP> <123@aiva.ed.ac.uk> Sender: news@sun.uucp Distribution: comp Lines: 43 > My copy of the draft C standard says (apropos of pointer comparisons): > > "If the objects pointed to are not members of the same aggregate object, the > result is undefined" The October 1, 1986 draft says this apropos of relational operators on pointers, but !NOT! apropos of equality operators. Does your draft says this even about comparisons for equality? > and that seems to apply here. Since this is a comparison for equality, it *doesn't* apply. It says, apropos of equality operators, If two pointers to objects or functions compare equal, they point to the same object or function, respectively. which pretty clearly indicates that comparison of pointers for equality is meant to work regardless of whether the two pointers point into the same array or not. > I assume this restriction is to allow segmented architectures to just > compare the segment offset (or is there another reason?). The restriction on *relational* operators is there because there may not be a straightforward order that can be imposed on addresses in general (either because the address space is segmented, or for any other reason); if the two addresses point to members of the same array, "less than" and "greater than" can be defined purely within the terms of the language by saying that pointer A is less than/greater than pointer B iff the array index of the object pointed to by pointer A is less than/greater than the array index of the object pointed to by pointer B. For *equality* operators, it is clear that they want to *forbid* segmented architectures from just comparing the segment offset; doing the comparison that way would be horribly bogus and stupid. So the answer is "yes, this is valid in all ANSI-conforming implementations." Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com