Is left and right shifting negative integers defined behavior?

You’re not reading that sentence correctly. The standard defines it if: the left operand has a signed type and a non-negative value and the result is representable (and previously in the same paragraph defines it for unsigned types). In all other cases (notice the use of the semicolon in that sentence), i.e, if any of these conditions isn’t verified, the behaviour is undefined.

Leave a Comment