order of evaluation

Tom Stockfisch tps at sdchem.UUCP
Sat Mar 7 09:14:34 AEST 1987


In article <616 at viper.UUCP> john at viper.UUCP (John Stanley) writes:

>... but I still feel that the standard should have rules
>which will allow a programmer to -know- the exact order of evaluation for
>any equation.  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....  I still feel that this is a significant
>failing in the language definition and would like to see a change.
>John Stanley (john at viper.UUCP)

I feel this is a significant *feature* of the language.  This issue has
been discussed recently, but I would like to summarize the pluses of
allowing expression rearrangement.  Most of the ideas below were contributed
by others, and thats all the more specific credit I can give since I didn't save
any of the postings.

1.  Most of the time, unless you are writing for one particular machine,
    the compiler knows better in what order to perform operations, since
    that order is machine-dependent.  An important feature of C is that
    not only is the correctness of a program portable among many machines,
    but usually its efficiency as well.  The local compiler chooses the
    method best for the local machine to implement your algorithm.

2.  You can write expressions in a way that best documents them for and
    explains them to other human readers.

3.  If you have complex multiple side effects in the same expression,
    you deserve what you get.

4.  There are two mechanisms available for when you really need to know
    the order:
	1)  Separate the expression into two statements.
	2)  Use the unary plus operator (when you get your ANSI compiler).

5.  If you want everything evaluated strictly from left to right, your
    thinking is too linear.


What are you are proposing is to remove an important feature that can't
be gotten at any other way.  Reliable execution order can be forced when
you really need it.  If we drop the rearrangement feature there is no
way to tell the compiler "I don't care how you do it, just get it done,
hopefully using the methods best for the machine on which you exist."
C currently provides both features, and since the "I don't care how..."
one is by far the more common one, it is very appropriately the default.

Who wants a language with fewer features (besides Ada users)?
Finally, if you were to remove this feature, there
    would be no way to get it back.  

|| Tom Stockfisch, UCSD Chemistry	tps%chem at sdcsvax.UCSD



More information about the Comp.lang.c mailing list