Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Dec 2002 05:10:53 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Ruslan Ermilov <ru@FreeBSD.ORG>
Cc:        "Andrey A. Chernov" <ache@nagual.pp.ru>, <bwk@bell-labs.com>, <obrien@FreeBSD.ORG>, <current@FreeBSD.ORG>
Subject:   Re: New AWK bug with collating
Message-ID:  <20021215050340.Y7950-100000@gamplex.bde.org>
In-Reply-To: <20021214131141.GD6946@sunbay.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021215050340.Y7950-100000>