This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: shifting
- From: Michel LESPINASSE <walken at zoy dot org>
- To: Marko Mlinar <markom at opencores dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 3 Jul 2002 23:39:32 -0700
- Subject: Re: shifting
- References: <004901c22323$876de930$0301010a@tyr>
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.