The future of 32-bit Linux
The future of 32-bit Linux
Posted Dec 5, 2020 14:57 UTC (Sat) by khim (subscriber, #9252)In reply to: The future of 32-bit Linux by warrax
Parent article: The future of 32-bit Linux
Surprisingly enough no. It's not an UB to convert from signed to unsigned type and back. When number is representable in both — conversion is guaranteed to keep it's value, if not — it's implementation-defined behavior, not undefined behavior.
This being said it's not all peach and roses. Unsigned type is “dominant”, if you mix signed and unsigned in the same expression results can be surprising, e.g. “u > -1” is almost always true because -1 is interpreted as 0xFFFFFFFF.
But no, there are no problems with UB.
Posted Dec 6, 2020 9:58 UTC (Sun)
by niner (subscriber, #26151)
[Link] (1 responses)
Posted Dec 8, 2020 22:01 UTC (Tue)
by khim (subscriber, #9252)
[Link]
The future of 32-bit Linux
Good catch. I was think about u >= -1. But "always false" also probably for what people expect when they write. And note: compilers are happy to “optimize” that code — but offer no warnings (except for specialized static analysis tools).
The future of 32-bit Linux