No warning promoting longs to long long in gcc
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-3.3 (Ubuntu) |
Invalid
|
Medium
|
Matthias Klose |
Bug Description
// this code can be found at http://
#include <stdio.h>
int main ( int argc, char *argv[] )
{ long long a;
int b=40;
a=1<<40; // this generates "warning: left shift count >= width of type",
implicitly promoted to 64.
printf( "a = %llx\n", a );
a=1<<b; // this generates no warning at all, and sets
a=1<<(b%32)=0x100 (different to the above case).
printf( "a = %llx\n", a );
a=1LL<<b; // this works as intended, seting a=0x10000000000
printf( "a = %llx\n", a );
}
// I've only tried this with <<, but I'd imagine other operators -
multiplication, for example - are similarly affected.
(In reply to comment #0) cjb.ie/ gcc-bug. c or cjb.ie/ gcc-bug. c.txt
> // this code can be found at http://
http://
>
> #include <stdio.h>
>
> int main ( int argc, char *argv[] )
> { long long a;
> int b=40;
> a=1<<40; // this generates "warning: left shift count >= width of type",
correct, the right hand side has type int.
> // but no warning about result of 32 bit expression being
> implicitly promoted to 64.
correct, you don't get a warning for promotion to the bigger type.
> // this sets a=1.
> printf( "a = %llx\n", a );
> a=1<<b; // this generates no warning at all, and sets
> a=1<<(b%32)=0x100 (different to the above case).
correct behaviour.
> printf( "a = %llx\n", a );
> a=1LL<<b; // this works as intended, seting a=0x10000000000
> printf( "a = %llx\n", a );
> }
>
> // I've only tried this with <<, but I'd imagine other operators -
> multiplication, for example - are similarly affected.