From -6256288434658948684
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c4044a0e79c89b37
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-12-26 13:28:41 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!colt.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: philippe_mori@hotmail.com ("Philippe Mori")
Newsgroups: comp.std.c++
Subject: Re: comparing signed and unsigned integral values
Date: Thu, 26 Dec 2002 21:28:38 +0000 (UTC)
Organization: Bell Sympatico
Lines: 24
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <ouKO9.2902$o51.788299@news20.bellglobal.com>
References: <f6aM9.81569$TA6.1061548@news.chello.at>
X-Trace: mail2news.demon.co.uk 1040938118 4125 10.0.0.1 (26 Dec 2002 21:28:38 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 26 Dec 2002 21:28:38 +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 18RfYS-00014O-00
	for mail2news@news.news.demon.net; Thu, 26 Dec 2002 21:28:37 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id IAA04953; Fri, 27 Dec 2002 08:28:29 +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.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-NNTP-Posting-Date: Thu, 26 Dec 2002 16:26:44 EST
X-Spam-Status: No, hits=-1.8 required=5.0
	tests=FORGED_HOTMAIL_RCVD,INVALID_MSGID,NOSPAM_INC,
	      PRIORITY_NO_NAME,REFERENCES,SPAM_PHRASE_02_03
	version=2.41
Xref: archiver1.google.com comp.std.c++:16428

In this case (I'm not sure what would be the rule if longs are 64 bit), both
values would be converted to unsigned before the comparison and -1 will
become a really big number and the comparison won't give the expected
result...

In pratice this is often the case when comparing signed and unsigned value,
we do not get the expected result.

For constants, I think that they are signed except when they do not fit the
range of signed value. The constant would be considered unsigned...

I do not think this could be easily changed. The best thing to do is to
properly select the appropraite type for your constants and variables
(either all signed or all unsigned). In some case, unsigned value could be
converted to signed value explicitly because we knows that it is not
probable to have a value bigger than the range of an unsigned. Better yet,
validate it before doing the conversion.

---
[ 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                       ]



