> The C99 (draft) standard says of << and
>> that "[t]he behavior is
> undefined if the right operand is negative, or greater than or equal
> to the length in bits of the promoted left operand"
I thought that C did NOT promote smaller operands, so
the behavior
was actually expected, once I saw what was really going on there.
C promotes operands...sometimes. The example works just fine if int is
64 bits, because then the default integral promotions promote the
32-bit value to 64 bits before the shift happens.
The "promoted left operand" in the quote refers to the left operand
after the default integer promotions. In this case this is a little
misleading, because (taken out of context, as here) it looks as though
it may be talking about promoting it to a type appearing somewhere
else, such as (in this case) the LHS of the assignment.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse at
rodents-montreal.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B