|
|
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
|
|