Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn
From: gwyn@brl-smoke.ARPA (Doug Gwyn )
Newsgroups: comp.lang.c
Subject: Re: ANSI C awkward examples
Message-ID: <6732@brl-smoke.ARPA>
Date: Wed, 25-Nov-87 16:53:57 EST
Article-I.D.: brl-smok.6732
Posted: Wed Nov 25 16:53:57 1987
Date-Received: Sun, 29-Nov-87 10:42:55 EST
References: <1470@copper.TEK.COM>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) )
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 33

In article <1470@copper.TEK.COM> timc@copper.UUCP (Tim Carver) writes:
>Fun things to know about ANSI C:

More precisely, about an early draft of what is intended to become the
ANS for the C programming language.  Read on...

>                (u + 1L) > 50 is false.

This was fixed in the November 9, 1987 draft.

>            For a typical 8086 implementation (32 bit long, 16 bit int)
>            if u_char_1 and u_char_2 each contain 200, the unsigned long
>            result in u_long is 4,294,941,760, instead of the correct
>            40,000.

Note that the integral promotions themselves preserve value
including sign, and the value of the unsigned chars are 200.
The only problem is that the multiplication overflows (the
result is not representable in an int).  Overflow is in the
"undefined" category, so the implementation may legally
produce either answer in this case.  Careful programmers
will provide explicit (unsigned) casts to ensure the
expected result.

If the "integral promotions" had been defined to preserve
sign rather than value, then your example would have worked
as you expected it to.  The decision to specify the value-
preserving rules was probably to most hotly debated X3J11
Committee decision, with AT&T on the side of the sign-
preserving rules.  However, the outcome was as you see it,
and now that it takes a 2/3 majority to make a substantive
change to the draft Standard, I doubt the likelihood of the
decision being reversed.