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 [EMAIL PROTECTED] :-)
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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to