[Bug c/69828] result of shift operation has wrong type
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Feb 15 19:58:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69828
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Let's look at the last one:
i8_t i = (argc < 0) | 0x80;
u8_t u = i;
i16_t t = (i16_t)u; << Not really there but useful otherwise.
<< This is a zero extend from u8 to i16 since u8 fits in i16 so
t = 0x80;
i32_t x32_c = t << 8;
t is prompted to int due to normal C promotion rules.
so t << 8 is the same as ((int)(0x80)) << 8 or
0x8000 aka 32768
printf("should be negative: %7d\n",x32_c);
So GCC is correct.
>The result of a shift operation should have the type of the left operand.
No, it should go though the standard C promotion rules. The standard promotion
rules says if the size of the type is less than int promote to int.
More information about the Gcc-bugs
mailing list