From 7816745175545221861
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c4044a0e79c89b37,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-12-18 20:08:25 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: georg@nospam.ucar.edu ("Georg D.")
Newsgroups: comp.std.c++
Subject: comparing signed and unsigned integral values
Date: Thu, 19 Dec 2002 04:08:20 +0000 (UTC)
Organization: Customers chello Austria
Lines: 41
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <f6aM9.81569$TA6.1061548@news.chello.at>
X-Trace: mail2news.demon.co.uk 1040270900 23730 10.0.0.1 (19 Dec 2002 04:08:20 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 19 Dec 2002 04:08:20 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18Oryt-0006AT-00
	for mail2news@news.news.demon.net; Thu, 19 Dec 2002 04:08:19 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id PAA27795; Thu, 19 Dec 2002 15:08:15 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4920.2300
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4920.2300
X-NNTP-Posting-Date: Thu, 19 Dec 2002 03:25:15 MET
X-Spam-Status: No, hits=2.3 required=5.0
	tests=INVALID_MSGID,MEMBER_2,NOSPAM_INC,PRIORITY_NO_NAME,
	      SPAM_PHRASE_00_01
	version=2.41
X-Spam-Level: **
Xref: archiver1.google.com comp.std.c++:16196

Hi,

The Standard says there are integral conversions (4.7) and what shall
happen if the destination is signed or unsigned, but I could not find
specification for the destination type of parameters of global comparison
operators, e.g. "bool operator < (???, ???)".

e.g. "-1 < 2294967295"   -> false (32-bit int)
with warning: comparing signed and unsigned values.

Q1: I'd like to understand which conversions are "performed" prior to
comparison.

Q2: while comparing signed and unsigned values could have a more
acceptable semantics, a C++ compiler will reject

    bool operator <(int x, unsigned y)
    {
        return x < 0 || (unsigned) x < y;
    }

    bool operator <(unsigned x, int y)
    {
        return y > 0 && x < (unsigned) y;
    }

with " 'operator <(int,unsigned int)' must be a member function or have a
parameter of class type" (Standard: 13.5/6)

I'd like to read your comments on this and/or get links to existing
comments or discussions.

TIA,
Georg

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]



