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

Ah, INT_MIN. If I had a nickel every time I saw an implementation of inttostr/strtoint that don't properly handle it, I'd probably have about $5. So I too thought about possibility of it serving as a NaN of signed integers... but I doubt we'll see it any time soon.

Also, apparently, shifting a negative number to the left is UB in C.



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.


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.




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

Search: