Shift by negative quantity

Barry Shein bzs at bu-cs.UUCP
Sat Jul 5 12:02:37 AEST 1986


Question: Is shifting by a negative quantity defined (that is,
probably means the other shift.) I could find no mention in K&R.

it came up with an expression like:

	foo = goo >> 10-PGSHIFT;

which was a constant shift value. it didn't work on a SUN3, what's the
poop? (seems hard for most code generators if it's variable, well,
would have to test and branch if the underlying machine's shift
instruction won't take negative values correctly so I wouldn't be
surprised if it's undefined and I could understand not wanting a
separate rule for a constant even though it would be easy to turn it
around.)

Therefore, I guess it's just not defined and you have to generate
your own test, but I was wondering what was official.

Of course, it accidently works right on a VAX and NS32k, great,
more bugs to worry about...(a test example forcing negative,
I know the above is positive on a VAX, that's the point ultimately.)

	-Barry Shein, Boston University

P.S. Is this one of those questions that gets asked every 2 months?
If so, I'm glad, maybe I'll get a good answer after all that practice :-)



More information about the Comp.lang.c mailing list