what is this supposed to do?
Erik Naggum
enag at ifi.uio.no
Thu Apr 25 02:10:44 AEST 1991
In article <1991Apr23.003314.5194 at zoo.toronto.edu>, Henry Spencer writes:
In article <1991Apr22.225641.1122 at midway.uchicago.edu>, Steve Langer writes:
>What is the expected output from the following program? Is it defined?
> printf("1 << 32 = %o\n", ((unsigned) 1) << 32);
Assuming you're on a 32-bit machine, no, it is undefined. Translation,
expect different machines to do different things, some of them unpleasant.
In concrete terms:
(1) Some machines treat the shift as "modulo word-length", i.e. 1 <<
32 => 1 << 0 => 1.
(2) Some machines treat the shift as an unsigned integer, and the
result as "modulo 2**wordlength", i.e. 1 << 32 => 4294967296 => 0.
(3) Some machines do something else when the shift operand is larger
than the applicable word-size, such as laugh at you.
--
[Erik Naggum] <enag at ifi.uio.no>
Naggum Software, Oslo, Norway <erik at naggum.uu.no>
More information about the Comp.lang.c
mailing list