Shifting: what's going on?

John Love-Jensen eljay@adobe.com
Thu Mar 29 15:11:00 GMT 2007


Hi Facundo,

> I expect to get a 1 in the s-th bit of a, and zeroes in all other
> bits. I don't know why you say that's an arithmetic overflow, if
> unsigned long long is 64 bits long and it has a 63-th bit (the last
> one).

You are not dealing with an unsigned long long that is 64-bits.

You are dealing with a signed int that is 32-bits.

Shifting a number by an amount equal-to-or-greater-than its bitsize has
undefined behavior.

--Eljay



More information about the Gcc-help mailing list