comma operator: keep away?

Gordon Cross crossgl at ingr.com
Thu Apr 20 23:15:38 AEST 1989


In article <828 at twwells.uucp> bill at twwells.UUCP (T. William Wells) writes:
>
>The thing that is wrong with the latter has little to do with
>mystification. What is wrong is that, for rapid and accurate
>understanding of code, one should avoid appearing to do more than one
>thing at a time.
>
>In other words, the physical layout of the code should make each thing
>being done appear distinct from all the other things being done.

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;
-- 

Gordon Cross             UUCP:      uunet!ingr!crossgl     "all opinions are
111 Westminister Way     INTERNET:  crossgl at ingr.com        mine and not those
Madison, AL 35758        MA BELL:   (205) 772-7842          of my employer."



More information about the Comp.lang.c mailing list