Shifting question

Doug Gwyn gwyn at brl-smoke.ARPA
Fri Jul 29 12:22:34 AEST 1988


In article <11592 at steinmetz.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
>| >	...If the value of the right operand is negative or is greater than or
>| >	equal to the width in bits of the promoted left operand, the behavior
>| >	is undefined.
>  So you have to build in an explicit check in every program, comparing
>the shift with the size of the item.

No; the vast majority of shifts in C applications do not require
the check.  However, if the language guaranteed the behavior you
want it to, then on many architectures a far larger percentage of
shifts would have to perform the check (in the compiler-generated
code).  This is one of the many cases where C is deliberately
permissive in order to allow a better fit to the hardware.  It is
of course not what an "ideal" programming language would do, where
"ideal" includes the notion of suitable hardware.



More information about the Comp.lang.c mailing list