Article View: comp.std.c++
Article #1278Re: Pointer comparisons
From: Stuart MacMartin
Date: Thu, 17 Dec 1992 15:16
Date: Thu, 17 Dec 1992 15:16
80 lines
4005 bytes
4005 bytes
In article <BzDs2x.wA@frumious.uucp> uunet.ca!frumious!pat writes: > > Two pointers to the same object compare equal. If two pointers ...but nowhere do I see a statement that (p == q) ==> p and q point to the same object, even if p and q are the same type. Is it possible for two objects of the same type to be in different segments and compare equal? >"Pointers ... may be compared". Does this mean any pair of pointers >may be compared, or some pairs may be compared? It certainly suggests >"any pair" to me, but some might interpret it as "some pairs". I interpreted this as "a compiler is permitted to allow comparisons of pointers not specified in this document", but I use the word "may" to mean "is allowed to", not "might", and I don't know the meaning of "may" in legalese. So yes, this wording is unclear to normal programmers. >Let me try to be constructive for a change. Would something >similar to the following be reasonable? (It would clearly need >much more careful wording and attention to details.) > >1) Any two pointers to the same type may be compared, with any of > the relational operators. > >2) In general, the results of the comparisons need not have anything > to do with the objects to which the pointers point. For example, > it is possible that p and q point to the same object, but p != q. > (But see below.) Note that this provides your counterexample for (p == q) <==> (ptrcmp(p,q) == 0) Also, I would expect OODBMSs to use object ids to determine the ordering, so if p and q point to the same object but p and q are of different types, we might allow ptrcmp(p,q) == 0. Or should equality mean "the same object and the same type"? This might be unnatural if the OODBMS has a different concept of type than C++; for example, if the type of the OODBMS handle (smart pointer) is used to say "use this object as if it were an object of type T" instead of the typical C++ usage: "use the type T part of this object". In the former case, the objects pointed to by the two pointers really are the same, even if one pointer has a restricted view of it. >3) The relational operators define a total ordering on the set of > pointers of each type. (All the normal rules, including > transitivity.) Is this possible? Mightn't some objects of one type be in one segment and some in another? (Perhaps I should say "practical", not "possible"). >4) If two pointers p and q (of the same type) are obtained through > sequences of "normal" operations, then > > p == q <==> p and q point to the same object I could not find this statement in the current wording. Is there a reason why the current wording is weaker than this? What do you mean by "normal" operations? What are examples of "abnormal" operations? >One might add a library function sameObject(p,q) which would >indicate whether p and q point to the same object, no matter >how p and q were obtained. Is this necessary if we have ptrcmp? If we like the name ptrcmp, shouldn't we like the name ptreq? If we like sameObject, perhaps we should like cmpUsingObjectOrder(p,q)? Also, if p = (Base *)q, should sameObject(p,q) be 1? Stuart -- : Stuart MacMartin email: sjm@bnr.ca : : Bell-Northern Research phone: (613) 763-5625 : : PO Box 3511, Stn C, Ottawa, K1Y-4H7, CANADA Standard disclaimers apply. :
Technical Details
Message-ID:
<1992Dec17.151642.9954@bcrka451.bnr.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!nott!bnrgate!bcrka451!bcrki65!sjmReferences:
<BzCG7K.2sG@frumious.uucp> <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!nott!bnrgate!bcrka451!bcrki65!sjm From: sjm@bcrki65.bnr.ca (Stuart MacMartin) Subject: Re: Pointer comparisons Message-ID: <1992Dec17.151642.9954@bcrka451.bnr.ca> Sender: 5E00 Corkstown News Server Organization: Bell-Northern Research Ltd., Ottawa, Canada References: <BzCG7K.2sG@frumious.uucp> <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> Date: Thu, 17 Dec 1992 15:16:42 GMT Lines: 80