More Re: Function Argument Evaluation argument
Geoffrey Rogers
grogers at convex.com
Wed Apr 3 00:03:13 AEST 1991
In article <18140 at crdgw1.crd.ge.com> volpe at camelback.crd.ge.com (Christopher R Volpe) writes:
>In article <RJOHNSON.91Apr1142143 at olorin.shell.com>, rjohnson at shell.com
>(Roy Johnson) writes:
+|>I understand that the comma operator is a sequence point.
+|>If we use the comma operator as a sequence point between evaluations:
+|>
+|> int v=1;
+|> printf("%d %d\n", (1, v), (1,v++));
+|>
+|>This can print
+|> 1 1
+|>or
+|> 2 1
+|>
+|>Do I win? 8^)
+
+Hey, that looks pretty good. No matter what the order of evaluation of
+the function arguments is, there's always a sequence point separating the
+references to v. So the behavior is not undefined, yet order of evaluation
+definitely has a drastic effect on the output.
+
+Anybody see a problem with that?
No.
In this case the compiler must evaluate 1 before it evaluate v or v++
in the subexpressions '(1,v)' and '(1,v++)'. But the order of
evaluation of these two subexpressions are still undefined.
+------------------------------------+---------------------------------+
| Geoffrey C. Rogers | "Whose brain did you get?" |
| grogers at convex.com | "Abbie Normal!" |
| {sun,uunet,uiucdcs}!convex!grogers | |
+------------------------------------+---------------------------------+
More information about the Comp.std.c
mailing list