From owner-freebsd-current Thu May 16 12:12: 3 2002 Delivered-To: freebsd-current@freebsd.org Received: from dragon.nuxi.com (trang.nuxi.com [66.92.13.169]) by hub.freebsd.org (Postfix) with ESMTP id A3CAD37B408; Thu, 16 May 2002 12:11:57 -0700 (PDT) Received: from dragon.nuxi.com (obrien@localhost [127.0.0.1]) by dragon.nuxi.com (8.12.3/8.12.2) with ESMTP id g4GJBvfg068445; Thu, 16 May 2002 12:11:57 -0700 (PDT) (envelope-from obrien@dragon.nuxi.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.12.3/8.12.3/Submit) id g4GJBvdX068444; Thu, 16 May 2002 12:11:57 -0700 (PDT) Date: Thu, 16 May 2002 12:11:57 -0700 From: "David O'Brien" To: Bill Fenner Cc: audit@FreeBSD.ORG, current@FreeBSD.ORG Subject: Re: moused(8): char signed-ness problem with gcc 3.1 Message-ID: <20020516121157.F67791@dragon.nuxi.com> Reply-To: obrien@FreeBSD.ORG Mail-Followup-To: David O'Brien , Bill Fenner , audit@FreeBSD.ORG, current@FreeBSD.ORG References: <200205160346.UAA27116@windsor.research.att.com> <86k7q48h2w.wl@archon.local.idaemons.org> <20020516114247.A67791@dragon.nuxi.com> <200205161906.MAA06850@windsor.research.att.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200205161906.MAA06850@windsor.research.att.com>; from fenner@research.att.com on Thu, May 16, 2002 at 12:06:49PM -0700 X-Operating-System: FreeBSD 5.0-CURRENT Organization: The NUXI BSD group X-Pgp-Rsa-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Rsa-Keyid: 1024/34F9F9D5 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 Thu, May 16, 2002 at 12:06:49PM -0700, Bill Fenner wrote: > >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 Sounds like you should forward this to gcc-bugs@gcc.gnu.org. :-) CC audit@ (and current@) so we can all see what the GNU people say. Don't forget to show the output of `cc -v'. Or run `gccbug' from a recient gcc31 port install. If you do this instead, please send me the PR #. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message