Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!gibbs!langer From: langer@gibbs.uchicago.edu (Steve Langer) Newsgroups: comp.lang.c Subject: what is this supposed to do? Keywords: left shift Message-ID: <1991Apr22.225641.1122@midway.uchicago.edu> Date: 22 Apr 91 22:56:41 GMT Sender: news@midway.uchicago.edu (NewsMistress) Reply-To: langer@control.uchicago.edu (Steve Langer) Organization: The James Franck Institute - The University of Chicago Lines: 32 Hi -- What is the expected output from the following program? Is it defined? #include main() { printf("1 << 32 = %o\n", ((unsigned) 1) << 32); } Running on a Sun 4 gives 1. Running on a Sun 3 gives 0. Running on an Iris gives 1. K&R (first edition) page 45 says that left shifts fill vacated bits by 0, which does not seem to be happening. If the shift is done one step at a time the answer is 0 on the Sun 4 and the Iris, as expected. #include main() { int i; unsigned x = 1; for(i=0; i<32; i++) x <<= 1; printf("%o\n", x); } E-mail responses are welcome! Thanks in advance, Steve langer@control.uchicago.edu