home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: Pointer comparisons
- Message-ID: <BzG0C8.I2@frumious.uucp>
- Date: Fri, 18 Dec 1992 06:50:32 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <1992Dec16.202711.22367@bcrka451.bnr.ca> <BzDs2x.wA@frumious.uucp> <1992Dec17.151642.9954@bcrka451.bnr.ca>
- Organization: None
- Lines: 91
-
- sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
- |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.
-
- Nor do I. But I think I once saw a discussion of this, and someone
- said this would be changed in a future version of the draft.
- (My memory of this is vague, though, so I may be imagining things.)
-
-
- |Is it possible for two objects of the same type to be in different
- |segments and compare equal?
-
- I would hope not, if they are different objects. But the draft
- seems to allow it.
-
-
- |>Would something
- |>similar to the following be reasonable? (It would clearly need
- |>much more careful wording and attention to details.)
- |>
- |>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)
-
- Yes, although this is under my proposal, not under the existing draft.
-
-
- |>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").
-
- I think it's possible, by doing bitwise comparisons of the pointers
- (ignoring padding, if any). Remember that so far, the comparisons
- don't have to be related in any way to the objects pointed to;
- I am _not_ asking for a total order on the address space.
-
-
- |>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?
-
- I don't know. The C standard requires both directions of the
- implication. I'm not sure if the concept "p and q point to
- the same object" is clearly defined anywhere.
-
-
- |What do you mean by "normal" operations?
- |What are examples of "abnormal" operations?
-
- These were described lower down in my previous posting.
- "Normal" operations are the ones whose semantics are defined
- by the standard; "abnormal" ones are the others.
-
-
- |>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?
-
- My idea with the above description of the operators was that ptrcmp
- would be unnecessary; the operators could be used instead.
-
-
- |Also, if p = (Base *)q, should sameObject(p,q) be 1?
-
- Yes. And also p == q should be 1. But note that before doing
- either comparison, q is converted to a Base* so that one has
- two pointers of the same type.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-