bits wrap when leftshifting non-constant amounts
Dag-Erling Smørgrav
des at des.no
Wed Feb 13 02:46:45 PST 2008
deeptech71 at gmail.com writes:
> My gcc 3.4.6 behaves weirdly when left shifting, and I couldn't find
> any info on this. [...]
It is very clear in ISO/IEC 9899:1999 §6.5.7:
3 The integer promotions are performed on each of the operands. The
type of the result is that of the promoted left operand. It the
value of the right operand is negative or is greater than or equal to
the width of the promoted left operand, the behaviour is undefined.
In other words, the result can be anything at all, and is not even
required to be consistent from one evaluation to the next. In fact, gcc
is free to wipe your hard drive, shoot your dog and burn down your house
for all the standard cares; which I guess is a roundabout way of saying
"don't do that".
DES
--
Dag-Erling Smørgrav - des at des.no
More information about the freebsd-chat
mailing list