Path: utzoo!attcan!uunet!ingr!crossgl From: crossgl@ingr.UUCP (Gordon Cross) Newsgroups: comp.lang.c Subject: Re: question about shift operator Message-ID: <2806@ingr.UUCP> Date: 2 Nov 88 14:30:22 GMT References: <786@gtx.com> Organization: Intergraph Corp. Huntsville, Al Lines: 24 In article <786@gtx.com>, randy@gtx.com (Randy D. Miller) writes: > I've seen conflicting information about the shift operator in cases > where operand2 is exactly equal to the number of bits in the object. > E.g., with a 32 bit int, what must the following do? > > int n; > n <<= 32; > > K&R 1st ed. seems to indicate the operation is undefined, but does > the proposed standard change this? K&R still applies. The proposed ANSI standard states: "If the right operand is negative or is greater than or equal to the width in bits of the promoted left operand, the result is implementation defined." Note the phrase "promoted left operand". This means that (assuming 16-bit shorts and 32-bit ints) the value of the expression "shortvar << 16" IS defined and has the same value as "shortvar * 0x10000"! Gordon Cross Intergraph Corp. Huntsville, AL