[m-dev.] for review: change semantics of integer shifts
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Mar 15 14:48:35 AEDT 1999
On 15-Mar-1999, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
>
> > I know that in ANSI C the result of `>>' is implementation defined (not
> > undefined) if the left operand is negative. But that is only because
> > ANSI C was supposed to work efficiently even on machines using one's
> > complement arithmetic. All modern machines use two's complement, and
> > so, I believe, all C implementations on these machines define `>>' for
> > negative left operands in the same way. Thus there is no good reason for
> > Mercury to make `>>' or even `unchecked_right_shift' have undefined
> > behaviour in the case where the left hand operand is negative.
>
> Depending on all C implementations on two's complement to define shift
> by a negative amount the same way would not be a good idea. On some machines,
> the shift amount is handled as unsigned, so what you think is a negative
> number will be treated as a large positive number.
I'm talking about shift *of* a negative amount (i.e. *left* operand negative),
not shift *by* a negative amount (i.e. *right* operand negative).
I agree that we should not depend on C implementations doing anything
sensible if the right-hand operand is negative or greater than or equal to
the word size.
Cheers,
Fergus.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list