Strange enum type conversion

Andrew Haley aph@redhat.com
Thu Dec 3 12:49:00 GMT 2009


John (Eljay) Love-Jensen wrote:

> Also be aware that if your "1 << 31" goal is to set the high bit, then your
> code is not portable.  If the platform has 64-bit int, you will instead be
> setting a middle bit.  If the platform has 16-bit int, such a shift is
> undefined behavior.

Isn't it UB on a 32-bit machine as well?  Looks like integer overflow to me.

Andrew.



More information about the Gcc-help mailing list