6 ms·
In C, shifting signed integers is undefined behavior.
by spc476 3y ago
In C, shifting signed integers is undefined behavior.
- compiler-guy 3y agoAlthough it can bite you if you don’t know what you are doing, signed-integer shifting is not necessarily undefined behavior. Roughly, for positive signed integers, if the operation doesn’t overflow then the result is defined. For negative signed numbers, right shifts are implementation defined, but almost all modern systems define the result in the expected manner. https://en.cppreference.com/w/cpp/language/operator_arithmetic https://en.cppreference.com/w/cpp/language/operator_arithmet...
- kps 3y agoOh, it's too bad C2x doesn't seem to be following C++20 here, since they're apparently mandating two's complement.