Xref: utzoo comp.lang.c:11407 comp.sys.ibm.pc:17324 Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!mailrus!tut.cis.ohio-state.edu!husc6!bbn!gatech!ncsuvx!ece-csc!jnh From: jnh@ece-csc.UUCP (Joseph Nathan Hall) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Bug list for Microsoft C Message-ID: <3721@ece-csc.UUCP> Date: 19 Jul 88 21:10:29 GMT References: <4516@pasteur.Berkeley.Edu> <372@scolex> <10807@iuvax.cs.indiana.edu> Reply-To: jnh@ece-csc.UUCP (Joseph Nathan Hall) Organization: North Carolina State University, Raleigh, NC Lines: 47 In article <10807@iuvax.cs.indiana.edu> bobmon@iuvax.UUCP (RAMontante) writes: seanf@sco.COM (Sean Fagan) writes: +iverson@cory.Berkeley.EDU.UUCP (Tim Iverson) writes: +>int i=1, j=33; +> +>main() { +> printf("%x\n", 1<<33); +> printf("%x\n", 1>>33); +> printf("%x\n", i< printf("%x\n", i>>j); +>} +>What results do you get? (This might even be interesting on non 86 machines; +>oh boy, I just checked a non 86, and it failed too.) + +Under Xenix '386, I get: 2, 0, 2, 0; using the '286 compiler, I get 0, 0, 2, +0. So, anybody, what does ANSI say (in plain English)? I tried reading the +draft to see what it should be, and I couldn't make head nor tail of it... +Somebody said, earlier, that both K&R and ANSI say the results are +implementation defined, but, from what I could stand of the draft, it didn't +seem to say that. And Turbo C v1.5 gave me 0 0 0 0 Something of a letdown, that. So what ARE the right numbers, and what is the right answer? First of all, you're not using a good example. See page 45 of K&R. The right-shift operation on SIGNED quanties is undefined. In the case of UNSIGNED quantities, the right-shift operation is supposed to fill vacated bits with zeros. Second, something is broken if 1 << 33 returns something other than 2^33 or 0, since for unsigned AND signed quantities, bits vacated during a left-shift operation are supposed to be filled with zero. My preferred result would be four zeros. Unless, of course, I had default 48- or 64-bit integers. -- v v sssss|| joseph hall || 201-1D Hampton Lee Court v v s s || jnh@ece-csc.ncsu.edu (Internet) || Cary, NC 27511 v sss || the opinions expressed herein are not necessarily those of my -----------|| employer, north carolina state university . . . . . . . . . . .