Strange enum type conversion

John (Eljay) Love-Jensen eljay@adobe.com
Thu Dec 3 12:56:00 GMT 2009


Hi Andrew,

> Isn't [(1 << 31)] UB on a 32-bit machine as well?  Looks like integer overflow
to me.

You know... I'm not sure.

I thought (1 << 31) was defined behavior on 2's and 1's complement machines.
I was an assembly bit-twiddler (6502, 65816, 680x0, and just a little bit of
80x86) back in the 70's and 80's (and some Alpha, PowerPC, and SPARC in the
90's... but not enough to brag about), so I tend to think in rather skewed
terms (e.g., I think of C as a powerful macro assembler).

But now that you brought it up*, I can't say that with strong confidence.
I'll have to research C (ISO 9899) and C++ (ISO 14882).

* Given the recent discussion about certain optimizations which perform
compilation analysis and do certain /a priori/ compiler knowledge range
optimizations based on UB that were a surprised** to the developer (the
"surprise" fixed by -fwrapv).

** And also news to me.  Good to be aware of the issue, although I am not
aware of having been stung by it.  Yet.

Sincerely,
--Eljay



More information about the Gcc-help mailing list