Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!ptimtc!nntp-server.caltech.edu!suncub.bbso.caltech.edu!EYCHANER From: eychaner@suncub.bbso.caltech.edu (Another casualty of applied metaphysics.) Newsgroups: comp.lang.c Subject: Re: Bug fix for Turbo C ? Message-ID: <1991Jun29.190505.10335@nntp-server.caltech.edu> Date: 29 Jun 91 19:05:05 GMT References: <1991Jun26.155139.86965@vaxc.cc.monash.edu.au>,<1991Jun29.123505.21528@thunder.mcrcim.mcgill.edu> Sender: news@nntp-server.caltech.edu Reply-To: eychaner@suncub.bbso.caltech.edu Organization: Big Bear Solar Observatory, Caltech Lines: 49 mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes: >The New Testament says, on page 206 (A7.8, Shift Operators): > > The value of E1>>E2 is E1 right-shifted E2 bit positions. The > right shift is equivalent to division by 2^E2 if E1 is unsigned > or if it has a non-negative value; otherwise the result is > implementation-defined. OK, I'm sorry, I just had to post on this one, since this, then, creates a problem for me (someday my code will break). I have the following piece of code (Please understand that this is just a fragment; any unwanted errors are probably my fault, and some things are the way they are for reasons I don't care to go into.): short a_250K_array[]; /* The big array */ int bit_shift, /* Bit shift */ array_size, i; /* Array size and index */ for (i = 0; i < arraysize; i++) { a_250K_array[i] >>= bit_shift; /* I shouldn't index the array like this; but it makes the code clearer */ } What I want is to divide each member of the 250K short array by 2^bit_shift. The 250K array contains both positive and negative numbers. In Vax C 3.0 (it's not the greatest, but it's adequate, OK?) section 7.5.7 SEEMS to guarantee that this works by filling the vacated bits with a copy of E1's sign bit (and indeed, from experience, it does work as expected). However, someday (dream on) Vax C might become ANSI standard, and I will need to change the way I do this. (Here, portability isn't a big issue, but having a system upgrade break code might be.) One qualifier: this loop must be FAST. And in my experience (so far), a_250K_array[i] /= (1 << bit_shift); isn't as fast as the first method. Is this the only ANSI legal way to do what I want to do? AARGH! This particular section of the standard puzzles me; why impose this seemingly unnecessary constraint on the shift operators? (Five thousand people will now write me explaining in great detail why it is necessary.) -G. ****************************************************************************** Glenn Eychaner - Big Bear Solar Observatory - eychaner@suncub.bbso.caltech.edu "There is no monopoly of common sense / On either side of the political fence" -Sting, "Russians"