Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.lang.c Subject: Re: what is this supposed to do? Message-ID: Date: 24 Apr 91 16:10:44 GMT References: <1991Apr22.225641.1122@midway.uchicago.edu> <1991Apr23.003314.5194@zoo.toronto.edu> Sender: enag@ifi.uio.no (Erik Naggum) Organization: Naggum Software, Oslo, Norway Lines: 20 In-Reply-To: henry@zoo.toronto.edu's message of 23 Apr 91 00: 33:14 GMT In article <1991Apr23.003314.5194@zoo.toronto.edu>, Henry Spencer writes: In article <1991Apr22.225641.1122@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] Naggum Software, Oslo, Norway