From 2687746352745794738
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c4044a0e79c89b37
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-12-30 21:42:14 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: nobody@localhost.ucar.edu (nobody)
Newsgroups: comp.std.c++
Subject: Re: comparing signed and unsigned integral values
Date: Tue, 31 Dec 2002 05:42:10 +0000 (UTC)
Organization: none
Lines: 27
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <200212310217.SAA04178@localhost.localdomain>
References: <7f2735a5.0212301238.c261aa9@posting.google.com>
X-Trace: mail2news.demon.co.uk 1041313330 18562 10.0.0.1 (31 Dec 2002 05:42:10 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 31 Dec 2002 05:42:10 +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 18TFAG-0004p6-00
	for mail2news@news.news.demon.net; Tue, 31 Dec 2002 05:42:08 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id QAA10829; Tue, 31 Dec 2002 16:41:54 +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-Spam-Status: No, hits=-6.4 required=5.0
	tests=NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01,
	      UNDISC_RECIPS
	version=2.41
Xref: archiver1.google.com comp.std.c++:16515

Allan W wrote:
> I've heard C++'s rules described as "preserved unsignedness." In other
> words, if one of your variables is unsigned, your comparisons will be
> unsigned.

That's not quite true.  C++ (and also ANSI C, from which the C++ rules
were inherited) requires that conversions be value-preserving whenever
possible.  For example, in a mixed expression containing int and
unsigned short everything will be promoted to int if possible, i.e.,
if sizeof(int) > sizeof(short);  but it sizeof(short) = sizeof(int)
everything gets promoted to unsigned int.  K&R C's rules, which were
unsigned-preserving, would have everything promoted to unsigned int
no matter what.

I know why the language is the way it is, but I often find myself
wishing that the rules were different and that all the integral
types had to be subranges of a signed type of maximum size so
that all conversions would be value-preserving.

nobody

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



