Date: Thu, 16 May 2002 12:06:49 -0700 From: Bill Fenner <fenner@research.att.com> To: obrien@FreeBSD.ORG Cc: knu@iDaemons.org, audit@FreeBSD.ORG, current@FreeBSD.ORG Subject: Re: moused(8): char signed-ness problem with gcc 3.1 Message-ID: <200205161906.MAA06850@windsor.research.att.com> References: <200205160346.UAA27116@windsor.research.att.com> <86k7q48h2w.wl@archon.local.idaemons.org> <20020516114247.A67791@dragon.nuxi.com>
next in thread | previous in thread | raw e-mail | index | archive | help
>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-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205161906.MAA06850>
