From owner-freebsd-current Sat Dec 14 10:10:11 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 71DE837B401; Sat, 14 Dec 2002 10:10:10 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1237143EC5; Sat, 14 Dec 2002 10:10:09 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id FAA20450; Sun, 15 Dec 2002 05:10:06 +1100 Date: Sun, 15 Dec 2002 05:10:53 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Ruslan Ermilov Cc: "Andrey A. Chernov" , , , Subject: Re: New AWK bug with collating In-Reply-To: <20021214131141.GD6946@sunbay.com> Message-ID: <20021215050340.Y7950-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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