...
The result of E1 >> E2
is E1
right-shifted E2
bit positions. If E1
has an unsigned type or if E1
has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1
/ 2
E2
. If E1
has a signed type and a negative value, the resulting value is implementation defined and may be either an arithmetic (signed) shift, as depicted in Figure 5—2, :
or a logical (unsigned) shift, as depicted in Figure 5—3
Figure 5—2. Arithmetic (signed) shift.:
This noncompliant code example fails to test whether the right operand is greater than or equal to the width of the promoted left operand, allowing undefined behavior.
...