Unexpected C/C++ bitwise shift operators outcome

1U << 32 is undefined behavior in C and in C++ when type unsigned int is 32-bit wide.

(C11, 6.5.7p3) “If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined”

(C++11, 5.8p1) “The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand.”

Leave a Comment