Order of evaluation and optimizing code

H. Munster dave at murphy.UUCP
Sat Nov 8 04:40:19 AEST 1986


I've read a number of letters in this column recently from people who would
like to see C obey a strict left-to-right, inside-to-outside order of
evaluation.  I wonder if they realize how much this sort of thing cripples
compilers in trying to optimize code.  C is one of the best, if not *the*
best languages in terms of compiled-code efficiency, and much of this is
due to the language standard allowing compilers to rearrange expressions
as they see fit, to eliminate redundant calculations and take advantage of
machine quirks and dependencies.  Please don't change it!

While on the subject, I have read about the proposed ANSI convention for
forcing evaluation "sequence points" by using the unary plus sign, and
I don't know how much I like it.  It does preserve compatibility in the
sense that code that uses it will compile on a compiler that doesn't know
about it...but will the compiled code work?  If the compiler does not
realize the significance of the unary plus and doesn't maintain the specified
order of evaluation, is the compiled code going to work?  Probably not.
Then the person who is doing the port has to scratch their head and try
to figure out what the problem is.  And, if they're not familiar with
the unary-plus convention, it's going to take a very long time to straighten
out.  I think that, in this case, it might have been better to invent a
new keyword or symbol to designate a sequence point, so that if the code
is ported to a compiler that doesn't have it, the problem will become
apparent immediately.  And before you send me a flame saying "BUT THAT 
WOULDN'T BE C!!!!", remember that Berkeley and other institutions have
already taken it upon themselves to add things that aren't in the
original K&R spec, such as structure assignment.  Are you going to tell
me that a compiler which allows structure assignment "isn't a C compiler"?

---
It's been said by many a wise philosopher that when you die and your soul
goes to its final resting place, it has to make a connection in Atlanta.

Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL
UUCP:  ...{sun,pur-ee,brl-bmd}!gould!dcornutt
 or ...!ucf-cs!novavax!houligan!dcornutt
ARPA: wait a minute, I've almost got it...

"The opinions expressed herein are not necessarily those of my employer,
not necessarily mine, and probably not necessary."



More information about the Comp.lang.c mailing list