Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!netcom!amdcad!dgcad!dg-rtp!webo!dg-webo!pds From: pds@lemming.webo.dg.com (Paul D. Smith) Newsgroups: comp.std.c Subject: Re: More Re: Function Argument Evaluation argument Message-ID: Date: 3 Apr 91 04:39:27 GMT References: <17936@crdgw1.crd.ge.com> <15607@smoke.brl.mil> <18140@crdgw1.crd.ge.com> Sender: usenet@webo.dg.com (Usenet Administration) Organization: NSDD/ONSD, Data General Corp., Westboro, MA Lines: 61 In-Reply-To: volpe@camelback.crd.ge.com's message of 2 Apr 91 13:24:16 GMT [ Hopefully I understand what you're saying here; if not please correct me... ] [] On 2 Apr 91 13:24:16 GMT, volpe@camelback.crd.ge.com (Christopher R Volpe) said: CRV> In article , rjohnson@shell.com CRV> (Roy Johnson) writes: CRV> |> CRV> |> int v=1; CRV> |> printf("%d %d\n", (1, v), (1,v++)); CRV> |> CRV> |>This can print CRV> |> 1 1 CRV> |>or CRV> |> 2 1 CRV> Hey, that looks pretty good. No matter what the order of CRV> evaluation of the function arguments is, there's always a CRV> sequence point separating the references to v. So the behavior is CRV> not undefined, yet order of evaluation definitely has a drastic ^^^^^^^^^^^^^ CRV> effect on the output. The behavior *is* indeed undefined in this case: Reference 1: ANSI X3.159-1989 Section 2.1.2.3, p. 8, lines 33-35: "At certain specified points in the execution sequence called _sequence points_, all side effects of previous evaluations shall ^^^^^^^^^^^^^^^^^^^^^ be complete and no side effects of subsequent evaluations shall have taken place." Reference 2: Ibid, Section 3.3.2.2, p. 42, lines 20-21: "The order of evaluation of the function designator, the arguments, ^^^^^^^^^^^^^^^^^^^ and subexpressions within the arguments is unspecified, ... " ^^^^^^^^^^^ So given the following statement: printf("%d %d\n", (1, v), (1, v++)); ^^^^^^ ^^^^^^^^ exp. 1 exp.2 The compiler is free to choose whether to evaluate exp.1 first, or whether to evaluate exp.2 first. Once it chooses it must indeed evaluate the "1" first, before the "v" or "v++". So it's still undefined whether this prints "1 1" or "2 1". And rightly so, IMHO! paul ----- ------------------------------------------------------------------ | Paul D. Smith | pds@lemming.webo.dg.com | | Data General Corp. | | | Network Services Development Division | "Pretty Damn S..." | | Open Network Systems Development | | ------------------------------------------------------------------