Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: question about shift operator Message-ID: <8820@smoke.BRL.MIL> Date: 2 Nov 88 17:43:23 GMT References: <786@gtx.com> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: na Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 23 In article <786@gtx.com> randy@gtx.UUCP (Randy D. Miller) writes: > n <<= 32; >K&R 1st ed. seems to indicate the operation is undefined, but does >the proposed standard change this? It's undefined because the intention is that a raw machine shift instruction be usable to implement this, and usually such a shift count cannot be represented in the instruction. I did see an architecture once that was unable to represent a 0 shift count, or rather you could build such an instruction but it didn't work right! However, the proposed C standard allows <<0 and >>0. (By the way, if the count is written as a constant, the compiler can sometimes use alternate code sequences, e.g. n <<= 16 becomes SWAP_HALVES CLEAR_LOWER and n <<= 100 could become CLEAR It is when a general expression is used for the count that things get interesting.)