This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Result of shift when operand == type size
- To: kai dot harrekilde-petersen at exbit dot dk
- Subject: Re: Result of shift when operand == type size
- From: Horst von Brand <vonbrand at inf dot utfsm dot cl>
- Date: Tue, 25 Apr 2000 12:01:19 -0400
- cc: gcc-bugs at gcc dot gnu dot org
"Kai Harrekilde-Petersen" <kai.harrekilde-petersen@exbit.dk> said:
> According to K&R (2ed), pg 206, the result of a shift,
> is undefined "if right operand is negative, or greater than or
> equal to the number of bits in the left expression's type"
> (A7.8 Shift Operators).
This is to allow just doing the shift; if the CPU gives garbage in these
cases, garbage is handled to the user. This way the compiler doesn't have
to go out of its way to check beforehand.
> GCC follows this a bit too faithfully, IMHO. Specifically,
> ~(~0ULL<<64) != ~0ULL. This complicates writing bitmask macros.
I'd assume your machine is doing this, not the compiler. Look at the
assembly code generated.
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513