This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Result of shift when operand == type size


"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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]