From -3849035065381660039
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c4044a0e79c89b37
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-12-27 13:02:36 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: nagle@animats.com (John Nagle)
Newsgroups: comp.std.c++
Subject: Re: comparing signed and unsigned integral values
Date: Fri, 27 Dec 2002 21:02:30 +0000 (UTC)
Organization: Prodigy Internet http://www.prodigy.com
Lines: 56
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <3E0C04E0.2040708@animats.com>
References: <f6aM9.81569$TA6.1061548@news.chello.at> <ouKO9.2902$o51.788299@news20.bellglobal.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1041022950 13476 10.0.0.1 (27 Dec 2002 21:02:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 27 Dec 2002 21:02:30 +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 18S1ci-0003VD-00
	for mail2news@news.news.demon.net; Fri, 27 Dec 2002 21:02:29 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id IAA26770; Sat, 28 Dec 2002 08:02:21 +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-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1
X-Accept-Language: en-us
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: Fri, 27 Dec 2002 02:41:21 EST
X-UserInfo1: SCSGW^_D\JUQB\D[NCOF_W\@PJ_^PBQLGPQRZ_MHEQR@ETUCCNSKQFCY@TXDX_WHSVB]ZEJLSNY\^J[CUVSA_QLFC^RQHUPH[P[NRWCCMLSNPOD_ESALHUK@TDFUZHBLJ\XGKL^NXA\EVHSP[D_C^B_^JCX^W]CHBAX]POG@SSAZQ\LE[DCNMUPG_VSC@VJM
X-Spam-Status: No, hits=-10.8 required=5.0
	tests=EMAIL_ATTRIBUTION,NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,
	      SPAM_PHRASE_02_03,USER_AGENT,USER_AGENT_MOZILLA_UA,
	      X_ACCEPT_LANG
	version=2.41
Xref: archiver1.google.com comp.std.c++:16444


===================================== MODERATOR'S COMMENT: 
 Please try not to quote moderation footers when posting.


===================================== END OF MODERATOR'S COMMENT
   I once wrote a paper titled "Type Integer Considered Harmful".
But it was too radical.  I addressed this issue by viewing
numeric types as ranges, and insisting that the compiler choose
intermediate types in expressions such that overflow in a
compiler-sized temporary was impossible unless an overflow in
the programmer-sized result was inevitable.  This usually
doesn't result in multiple-precision arithmetic, and when
it does, you needed it.  The "size of the machine" would
then no longer be visible to the programmer.

   Too radical, and, once the ones-complement and the
36-bit machines died off, unnecesssary.

					John Nagle
					Animats

Philippe Mori wrote:

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

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



