On Dec 18, 2006, at 9:24 AM, Robert Dewar wrote:
Chris Lattner wrote:
Sorry, but you're incorrect. While it may be "logical" that
shifting a value left more bits than its size will give you zero,
this is not what C specifies.
I am puzzled, what exactly *does* C specify in this case? I reread
the thread, but it's not clear what the requirement of the standard
here is (as opposed to what programmers might or might not expect,
or what hardware does or does not do).
C99 says:
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.
Thus, it is undefined.
-Chris