[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (1 << -1) ?
> Date: Mon, 16 Sep 2002 09:31:15 +0200 (MET DST)
> From: Per Zander <firstname.lastname@example.org>
> On Sat, 14 Sep 2002, Hans-Peter Nilsson wrote:
> > > Date: Sat, 14 Sep 2002 16:36:04 +0200
> > > From: Sebastian Andersson <email@example.com>
> > > printf("%u\n", 1<<(-1));
> > > gives 0 the cris and 2147483648 on i386.
> > > Since gcc gives a warning about this, I assume the result
> > > is undefined in the ISO C standard, is that correct
> > Yes.
> If I remember correctly, the shift operation in ISO C is defined for
> shifts from 0 up to and including the number of bits in the shifted
> operand. Am I right ?
6.5.7 Bitwise shift operators
... "If the value of the right operand is negative or is greater
than or equal to the width of the promoted left operand, the
behavior is undefined."
Not only the CRIS instruction set but also GCC internals may
come in play here, since all operands are constant. That is,
the result may change in a new GCC release.