Subject: Re: gcc/egcs problem with shifts on i386
To: Colin Wood <cwood@ichips.intel.com>
From: None <seebs@plethora.net>
List: current-users
Date: 08/16/1999 23:10:24
In message <199908170400.VAA32592@pdxcs200.pdx.intel.com>, Colin Wood writes:
>i wrote a little program to play with shifts today (i needed it for work)
>and discovered a problem with shifts under i386 (or IA32 as we like to say
>here at work ;-)  the program is included below for reference.  what i've
>found is that if i specify a shift count of 32 for either a right or left
>shift (i.e num << 32), i get back the same number i put in, rather than a
>0.

I see no problem here.  For n-bit numbers, C says that shifts of n bits are
undefined behavior.

>this only appears to occur on i386 (and i can probably explain it fairly
>easily if a shift is implemented via SHL/SHR).  what i'm wondering is if
>this is a bug in egcs/gcc, or if this is simply a hole in the C spec and
>either behavior is allowed.

It's not a hole, it's a feature.  :)

-s