shift left arithmetic

Peter Holzer hp at vmars.tuwien.ac.at
Wed Sep 12 01:30:13 AEST 1990


bomgard at copper.ucs.indiana.edu (Tim Bomgardner) writes:

>}#>I stumbled over the following: 1<<32 produced 0, but
>}#>int a; a=1; a<<32 produced 1. (Of course the word length

>For those who might be interested:

>Microsoft C (5.1) produced different results depending on the use of 16
>or 32 bit integers, but at least one case would always produce a
>non-zero result.  Turbo C 2.0 always produced 0's in all cases.

On the same computer?

On the 8086, all bits of the bit count are significant, so the result should
be 0. On a 80386, however only the rightmost 5 bits are taken, so the result
should be 1 (Of course the 8086 only has 16 bit words, so 32bit shifts are 
done by a library function, which might mask out all but the lower 5 bits;
and neither TC 2.0 nor MSC 5.1 can produce 80386 code, so a 32bit shift is
never done in one instruction with these compilers).
--
|    _	| Peter J. Holzer			| Think of it	|
| |_|_)	| Technische Universitaet Wien		| as evolution	|
| | |	| hp at vmars.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!vmars!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list