Reputation: 3
Reference: Suffix in Integer Constants
unsigned long long y = 1 << 33;
Results in warning:
left shift count >= width of type [-Wshift-count-overflow]
Two Questions need to be cleared from the above context:
Upvotes: 0
Views: 119
Reputation: 29985
In C language, 1 is an int
which is 32 bits on most platforms. When you try to shift it 33 bits before storing its value in an unsigned long long
, that's not going to end well. You can fix this in 2 ways:
1ULL
instead, which is an unsigned long long
constant:unsigned long long y = 1ULL << 33;
unsigned long long y = 1;
y <<= 33;
Both are valid, but I'd suggest the first one since it's shorter and you can make y
const.
Upvotes: 3