From 412909199891997374
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,221e73cda6c65dc7,start
X-Google-Attributes: gidf78e5,public
From: "Boris" <boris@gtemail.net>
Subject: relational operators and pointers
Date: 2000/06/21
Message-ID: <8iog9l$2bo$1@news.rrz.Uni-Koeln.DE>#1/1
X-Deja-AN: 636915605
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Priority: 3
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 961529385 mail2news:16676 mail2news mail2news.demon.co.uk
Organization: GTEmail.net
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-MSMail-Priority: Normal
NNTP-Posting-Date: 20 Jun 2000 19:22:29 GMT
Newsgroups: comp.std.c++

The C++ Standard says somewhere:
"For templates greater, less, greater_equal, and less_equal,  the
specializations for any pointer type yield a total order, even if the
built-in operators <, >, <=, >= do not."
Does this implicitly mean that == and != are ok for comparing pointers no
matter what pointers are compared?

Somewhere else I found:
"If two pointers p and q of the same type point to the same object or
function [...] then p<=q and p>=q both yield true and p<q and  p>q  both
yield false."
This is in C++:
A *p1 = new A;
A *p2 = p1;
p1 == p2;  // true
p1 != p2; // false

But then the Standard says:
"If two pointers p and q of the same type point to different objects that
are not members of the same object [...] the results of p<q, p>q, p<=q, and
p>=q are unspecified."
In C++:
A *p1 = new A;
A *p2 = new A;
p1 == p2; // unspecified
p1 != p2; // unspecified

But this is stupid as you are allowed only to compare pointers that point to
the same object because the rest is unspecified. That means you have to know
whether pointers point to the same object before you compare them! Do I
misunderstand the Standard (I really hope so)?

Boris


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




