Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!uflorida!novavax!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: comma operator: keep away? Message-ID: <839@twwells.uucp> Date: 21 Apr 89 14:23:01 GMT References: <10007@smoke.BRL.MIL> <498@lakart.UUCP> <10057@smoke.BRL.MIL> <628@gonzo.UUCP> <28831@ucbvax.BERKELEY.EDU> <828@twwells.uucp> <5053@ingr.com> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 63 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <5053@ingr.com> crossgl@ingr.UUCP (Gordon Cross) writes: : I'd like to make one small observation about Mr. Wells' above comment. In : certain cases where execution speed is of primary importance and you don't : have the time or energy to code in assembler (God forbid!) the vast majority : of compilers (that I've seen anyway) tend to generate better code for a single : complex expression that accomplishes multiple (related) tasks than for the : equivalent multiple simple expressions. For example an "insert into doubly : linked list" operation on my compiler: : : This one used 4 instructions - : : (new->next = next)->prev = (new->prev = prev)->next = new; : : This one used 7 instructions - : : new->next = next; : new->prev = prev; : next->prev = new; : prev->next = new; But, counterintuitively, one VAX compiler given the following: x = y = z = 0; generated worse code than x = 0; y = 0; z = 0; Why? Because the compiler chose to interpret the first one according to its letter rather than its spirit, generating: move z,0 move y,z move x,y instead of the better: move z,0 move y,0 move x,0 or even: move register,0 move z,register move y,register move x,register And the compiler that did this would have compiled both of the examples with only four instructions. The moral? Unless you a) have reason to believe that the speed is going to make a difference, and b) are willing to read assembly code to verify that your coding hack really makes a difference, follow your style rules rather than doing speed hacks. --- Bill { uunet | novavax } !twwells!bill (BTW, I'm may be looking for a new job sometime in the next few months. If you know of a good one where I can be based in South Florida do send me e-mail.)