Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!aurora!labrea!agate!ucbvax!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.lang.c Subject: Order of evaluation of nested function arguments Message-ID: <3995@hoptoad.uucp> Date: 2 Feb 88 13:02:47 GMT Organization: Nebula Consultants in San Francisco Lines: 51 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. This is probably an unintended consequence of the "no interleaving" rule, which as I recall was written for cases involving ?: in getc(). For all I know, the wording has been modified in future draft standards which are as yet unavailable to the public. Richard claims the order of evaluation here is undefined. Anybody know? Anybody care? Here's the test program (gnu12.c), which gcc-1.17 "fails" if I am correct. John /* Ackerman's function */ main() { int i; i = A(3,6); if (i == 509) printf("Test passed\n"); else printf("FAILED ackerman's(3, 6): %d\n", i); } A(x,y) int x,y; { if(x==0) return(++y); if(y==0) return(A(--x,1)); return(A(--x,A(x,--y))); } -- {pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu gnu@toad.com "Watch me change my world..." -- Liquid Theatre