Re: Strange bit shifting result with gcc - am I missing something obvious?
- From: lawrence.jones@xxxxxxxxxxx
- Date: Sun, 30 Mar 2008 17:56:38 -0400
Boltar <boltar2003@xxxxxxxxxxx> wrote:
On 32 bit linux with gcc 4.2 I get unexpected results with this code:
main()
{
int bits = 32;
printf("%d\n",(int)1 << (int)32);
printf("%d\n",(int)1 << bits);
}
The first printf gives a result of 0, the second gives 1. I checked
with sizeof() and ints are definately 32 bits in size.
I'm sure I'm missing something obvious but can someone tell me what?
That the shift count must be *less than* the number of bits in the
operand or you get undefined behavior.
-Larry Jones
Please tell me I'm adopted. -- Calvin
.
- References:
- Prev by Date: Re: Reentrant functions and memory allocation
- Next by Date: Re: ?: as an lvalue
- Previous by thread: Re: Strange bit shifting result with gcc - am I missing something obvious?
- Next by thread: sizeof(x)
- Index(es):
Relevant Pages
|
|