Hacker News new | ask | show | jobs
by Dylan16807 42 days ago
Left shifting a large positive number is also UB. C made a lot of things undefined that would make much more sense as implementation defined.
1 comments

Yep. Basically, if you take a signed int/long/etc. and a set bit shifts left into the sign bit — UB.

> a lot of things... would make much more sense as implementation defined.

Or even just defined. Apparently, the fact that shifting right a signed number is done arithmetically, not logically, is implementation-defined too.

Well, at lest bitwise not/and/or are (almost) fully defined even for signed integers, so that's something.

Well at the time it made sense not to force two's complement. But I would try harder to trim the UB list over time.