Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Feb 2008 11:46:38 +0100
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        deeptech71@gmail.com
Cc:        freebsd-chat@freebsd.org
Subject:   Re: bits wrap when leftshifting non-constant amounts
Message-ID:  <86abm56smp.fsf@ds4.des.no>
In-Reply-To: <47B24480.9020001@gmail.com> (deeptech's message of "Wed\, 13 Feb 2008 02\:14\:40 %2B0100")
References:  <47B24480.9020001@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
deeptech71@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 =C2=A76.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
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86abm56smp.fsf>