order of evaluation

Alan J Rosenthal flaps at utcsri.UUCP
Sun Mar 8 17:11:06 AEST 1987


In article <616 at viper.UUCP> john at viper.UUCP (John Stanley) writes:
>I still feel that the standard should have rules
>which will allow a programmer to -know- the exact order of evaluation for
>any equation.

It does.. use temporaries.  For example, if you want the sum a+b+c evaluated
in the order implied by (a+b)+c, simply write two statements, the first of
which is t=a+b; and the second of which contains the expression t+c.  (If you
have a REALLY good optimizer it's possible that this temporary variable will be
optimized out completely.  In any case, the redundant store/load will probably
be optimized out.)

>I know this is not likely for the sole reason that there
>are too many different compilers already existing that do the ordering in
>far too many different ways.

Also for the reason that there is quite likely a different best order for
different machines, so the compilers should be free to implement the best
order for their machine.

-- 

Alan J Rosenthal

UUCP: {backbone}!seismo!mnetor!utgpu!flaps, ubc-vision!utai!utgpu!flaps,
      or utzoo!utgpu!flaps (among other possibilities)
ARPA: flaps at csri.toronto.edu
CSNET: flaps at toronto
BITNET: flaps at utorgpu



More information about the Comp.lang.c mailing list