From owner-freebsd-audit Thu May 16 12: 7: 0 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mail-blue.research.att.com (mail-blue.research.att.com [135.207.30.102]) by hub.freebsd.org (Postfix) with ESMTP id 3E32437B400; Thu, 16 May 2002 12:06:54 -0700 (PDT) Received: from alliance.research.att.com (alliance.research.att.com [135.207.26.26]) by mail-blue.research.att.com (Postfix) with ESMTP id 8531D4CE67; Thu, 16 May 2002 15:06:50 -0400 (EDT) Received: from windsor.research.att.com (windsor.research.att.com [135.207.26.46]) by alliance.research.att.com (8.8.7/8.8.7) with ESMTP id PAA21556; Thu, 16 May 2002 15:06:49 -0400 (EDT) From: Bill Fenner Received: (from fenner@localhost) by windsor.research.att.com (8.8.8+Sun/8.8.5) id MAA06850; Thu, 16 May 2002 12:06:49 -0700 (PDT) Message-Id: <200205161906.MAA06850@windsor.research.att.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII To: obrien@FreeBSD.ORG Subject: Re: moused(8): char signed-ness problem with gcc 3.1 Cc: knu@iDaemons.org, audit@FreeBSD.ORG, current@FreeBSD.ORG References: <200205160346.UAA27116@windsor.research.att.com> <86k7q48h2w.wl@archon.local.idaemons.org> <20020516114247.A67791@dragon.nuxi.com> Date: Thu, 16 May 2002 12:06:49 -0700 Versions: dmail (solaris) 2.4/makemail 2.9b Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG >Specifically what is the problem? Given the program below, take the >ISO-C spec and explain the problem. Or even w/o the spec -- I haven't >been reading this thread. > > int > > main() > > { > > unsigned char i = 127; > > char j; > > > > printf("%d\n", ((char)(i << 1))); This prints -2, which is correct -- (signed char)254 is -2. > > j = ((char)(i << 1)) / 2; > > printf("%d\n", j); This prints 127, which is incorrect. -2 / 2 is -1. > > j = ((char)(i << 1)); > > printf("%d\n", j / 2); This breaks down the previous expression into two halves, and results in the correct answer of -1. However, there should be no difference between ((char)(i << 1)) / 2 and char j = ((char)(i << 1); j / 2 Bill To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message