From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,THIS_AD autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1cf653444208df72 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-12 18:12:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!jfk3-feed1.news.digex.net!dca6-feed2.news.digex.net!intermedia!newsfeed1.cidera.com!Cidera!cyclone.nyroc.rr.com!news-east.rr.com!wn2feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail From: "David Thompson" Newsgroups: comp.lang.ada References: <9q7na102nqn@drn.newsguy.com> <87k7xwa93z.fsf@deneb.enyo.de><9cLA7.135653$3d2.4077683@bgtnsc06-news.ops.worldnet.att.net> <87hess6tqf.fsf@deneb.enyo.de> Subject: Re: ada vs. cpp X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: Date: Tue, 13 Nov 2001 02:12:00 GMT NNTP-Posting-Host: 12.89.171.190 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1005617520 12.89.171.190 (Tue, 13 Nov 2001 02:12:00 GMT) NNTP-Posting-Date: Tue, 13 Nov 2001 02:12:00 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:16389 Date: 2001-11-13T02:12:00+00:00 List-Id: (This is getting pretty far offtopic.) Florian Weimer wrote : > "David Thompson" writes: > > > But on a machine with 32-bit char and 32-bit (or smaller?!) int, > > this promotion no longer happens, so UCHAR_MAX + 1 is > > always zero, and the loop never executes. > > Is it always zero? I don't think so. For example, UCHAR_MAX itself > could equal zero when cast to an unsigned integer type (on a ones > complement machine). > "Always" under the (rather restrictive) environment I stated, yes. More precisely, if unsigned char does not "fit" in signed int. UCHAR_MAX (and all the other integer MAX and MIN macros) cannot equal zero. They have "the same type as would an expression that is an object of the corresponding type converted according to the integer promotions" 5.2.4.2.1p1 and those promotions are value-preserving 6.3.1.1p2,3. The representation used for unsigned integer types must be "pure binary" 6.2.6.2p1; the possibly ones-complement representation of signed integers only applies to a signed integer type, which in this environment UCHAR_MAX is not. If you (explicitly) cast it to signed int, _then_ it might be zero (and is certainly implementation-defined). And in this environment, where UCHAR_MAX promotes to unsigned int not signed, this also means (which I elided) the addition UCHAR_MAX + 1 is done in unsigned int; this is a specific width (not universal) and in C unsigned integer overflow is required to wrap modulo 2 up W while signed or floating overflow is Undefined Behavior (erroneous). Therefore in this environment the result is zero (with the undesirable consequences already discussed). -- - David.Thompson 1 now at worldnet.att.net