question about shift operator

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Nov 3 03:43:23 AEST 1988


In article <786 at gtx.com> randy at gtx.UUCP (Randy D. Miller) writes:
>     n <<= 32;
>K&R 1st ed. seems to indicate the operation is undefined, but does
>the proposed standard change this?  

It's undefined because the intention is that a raw machine shift
instruction be usable to implement this, and usually such a shift
count cannot be represented in the instruction.  I did see an
architecture once that was unable to represent a 0 shift count,
or rather you could build such an instruction but it didn't work
right!  However, the proposed C standard allows <<0 and >>0.

(By the way, if the count is written as a constant, the compiler
can sometimes use alternate code sequences, e.g.
	n <<= 16
becomes
	SWAP_HALVES
	CLEAR_LOWER
and
	n <<= 100
could become
	CLEAR
It is when a general expression is used for the count that things
get interesting.)



More information about the Comp.lang.c mailing list