Order of evaluation of nested function arguments

Jerry Schwarz jss at hector.UUCP
Thu Feb 4 04:03:49 AEST 1988


In article <3995 at hoptoad.uucp> gnu at hoptoad.uucp (John Gilmore) writes:
>Richard Stallman and I have a disagreement over whether the ANSI
>standard specifies an order of evaluation for this statement
>(taken from an implementation of Ackermann's function):
>
>	return(A(--x,A(x,--y)));
>
>In the oct 86 draft standard, it says that (3.3) "the evaluation of the
>operands of an operator that involves a sequence point shall not be
>interleaved with other evaluations".  The function call operator
>clearly involves a sequence point (3.3.2.2) "The order of evaluation of
>the function designator, the arguments, and subexpressions within the
>arguments is unspecified, but there is a sequence point before the
>actual call".
>
>This means to me that A(x,--y) must be evaluated before the --x,
>because the evaluation of A, x, and --y for the inner function call
>cannot be interleaved with the evaluation of A, --x, and A(x,--y) for
>the outer one.
>

Your interpretation is not consistent.  It would mean that there was
no way to evaluate F(F(x),F(y)), because you would require F(x) to be
evaluated before F(y) and visa versa.

What the draft standard is saying is that the evaluations A, x, --y
and the function call must occur as a unit.  For example it is
prohibiting  the order  "A, x, --x, --y, call".  The orders
"--x,A,x,--y,call" and "A,x,--y,call,--x" are both allowed since the
relevant evaluations are not "interleaved" with other evaluations
but are performed either before or after.

I'm pretty sure that the example of concern to the committee was
something like

	((a=5),a) + ((a=6),a)

PCC derived compilers tend to evaluate this in the order "a=5",
"a=6", "a", "a", "do the sum".   The words quoted above from the
draft standard would disallow that order.

Jerry Schwarz



More information about the Comp.lang.c mailing list