3 ms·
AFAIK, assuming a 32-bit integer, 0x80000000 triggers undefined behavior. It might produce INT_MIN, blow up your computer, bring world peace, etc. It is true th
by Someone 15y ago
AFAIK, assuming a 32-bit integer, 0x80000000 triggers undefined behavior. It might produce INT_MIN, blow up your computer, bring world peace, etc. It is true that many implementations do modular arithmetic, but assuming that makes your code platform dependent. So, I think you would be past that thin line.
I think -0x80000000 is perfectly valid, but that depends on the grammar. If that gets parsed as "apply negation operator to 0x80000000", it triggers undefined behavior. If it gets parsed as a negative constnat value, things are OK.
In either case, chances are INT_MIN is the better way to write it.