This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: shifting


On Thu, Jul 04, 2002 at 08:25:01AM +0200, Marko Mlinar wrote:
> About some time I noticed gcc has strange "feature" with shifting.
>   volatile int a = 20;
>   volatile int b = 20;
>   const int x = 0xdeaddead;
>   const int c = 40;
>   printf ("%08x %08x\n", (x >> a) >> b, x >> c);

This is a C feature. Shifting an integer type by a value higher than
the bit width of that type gives undefined results. So in your example
the first integer should always be 0xffffffff, but the second one is
undefined and could be anything.

-- 
Michel "Walken" LESPINASSE
Is this the best that god can do ? Then I'm not impressed.


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