C problem, order of evaluation

Karl Heuer karl at haddock.ima.isc.com
Tue Apr 10 06:54:14 AEST 1990


In article <19539 at grebyn.com> ckp at grebyn.UUCP (Checkpoint Technologies) writes:
>In article <1990Apr8.185047.7385 at diku.dk> null at diku.dk (Niels Ull Jacobsen) writes:
>>"( stack[++sp]= exp , stack[sp -= N])", where exp contains N "stack[++sp]"'s.
>
>As long as that comma is really the comma *operator* and not the
>function argument separator, then the order of evaluation of your
>subexpressions *is* guaranteed....

I think the problem was with the multiple references to `sp' on the left side
of the comma.  Niels: am I correct in assuming that
	(stack[++sp] = stack[++sp] + stack[++sp], stack[sp -= 2])
is an example of the generated code?

My recommendation is to force your translator to generate code like
	(++sp, stack[sp] = stack[sp+1] + stack[sp+2])
instead.  That's the only way to be sure that the compiler knows what you're
talking about.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list