Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C, shifting signed integers is undefined behavior.


Although 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_arithmet...


Oh, it's too bad C2x doesn't seem to be following C++20 here, since they're apparently mandating two's complement.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: