bug?

David Berthelot davidb@Magma-DA.COM
Fri Jun 15 16:38:00 GMT 2001


Hi Ben,

as far as I know, arguments are ints for printf,
so the destination 'variable' if there was one, would
be an int.
So in fact your data is 32 bits for your printf, that is
not equivalent to your lines of code which results are
stored into a short.

So I think, everything's correct.

Try:

printf("%x\n", ((unsigned short)(s<<8))>>8);

David

Ben Kohlen wrote:

> I am expecting that when I shift right, I will always
> get zeroes in from the left, but when I use data types
> less than 32 bits, this is not always the case.
>
> Example:
> ...
> unsigned short s = 0xcc55;
> printf("%x\n", (s<<8)>>8);
> ...
> yeilds the output "cc55" where as I was expecting
> "55".
>
> I was expecting this to be equivalent to:
> ...
> s = s << 8;
> s = s >> 8;
> ...
> in which you do explicit assignment, which does yeild
> "55" as the output.
>
> Is this part of C spec, unspecified by C, or actually
> a gcc bug?
>
> gcc version 2.95.3 20010315 (release) on an x86 btw.
>
> Please CC responses, as I am not on the list.
>
> Cheers,
> Ben
>
> __________________________________________________
> Do You Yahoo!?
> Spot the hottest trends in music, movies, and more.
> http://buzz.yahoo.com/



More information about the Gcc-help mailing list