C
Charlie Gordon
The C standard defines a<<b to be a shift operations, and further
defines that it will be equivalent to ((a*(2**b))mod Uxxx_MAX) for
unsigned a's and non-negative b's.
For signed first operands, if the first operand is non-negative, and
if the result of (a*(2**b)) is representable in the type, then that's
the result. Otherwise (in the case of overflow or negative first or
second operands) the result is undefined.
In both cases, shift counts larger than the first parameter's width in
bits also have undefined results.
larger or equal.
6.5.7p3:
The integer promotions are performed on each of the operands. The type of
the result is
that of the promoted left operand. 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.
On a 'regular' 32-bit machine, we have this:
0 << 31 defined, result is 0
1u << 31 defined, result is 0x80000000u
1 << 31 undefined behaviour
1 << -1 undefined behaviour
0 << 32 undefined behaviour