On Sat, 14 Dec 2002, Ruslan Ermilov wrote: > On Sat, Dec 14, 2002 at 09:02:40PM +1100, Bruce Evans wrote: > > For ANSI C, the result of the subtraction only depends on the width > > of unsigned char. If unsigned char has the same width as int, then > > the result is UINT_MAX; otherwise the result is -1. This is an example > > of the brokenness of "value preserving" conversions -- the value is > > as far as possible from being preserved.
> Hmm, then how you could explain the difference between -traditional > and -ansi outputs for the following fragment on i386: > > int printf(char *, ...); > > int > main(void) > { > long long l; > unsigned char c1 = 1; > unsigned char c2 = 2; > > l = c1 - c2; > printf("%lld\n", l); > l = -1; > printf("%lld\n", l); > } > > Or the same code but with `long' on sparc64. The first paragraph above is all about the ANSI C case. -traditional gives signedness-preserving conversions, so c1 is prompted to 1U and c2 is promoted to 2U. 1U - 2U is UINT_MAX on all machines. The difference between UINT_MAX and -1 can be seen by converting these values to a common wider type as in your example. UINT_MAX < LLONG_MAX on all machines supported by FreeBSD although not in general, so assigning it to `l' doesn't change its value. Bruce To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message