Function Argument Evaluation
Stephen Clamage
steve at taumet.com
Fri Mar 22 04:07:36 AEST 1991
jdp at polstra.UUCP (John Polstra) writes:
| #include <stdio.h>
| int x = 100, y = 200, *p;
| main() {
| printf("%d %d\n", *(p = &x), *(p = &y));
| }
|Could a conforming compiler translate this in such a way that the output
|of the program is "200 200"?
|I believe it could, based on this quote from section 3.3.2.2 of the
|October 31, 1988 draft:
| 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.
The statement is identical in the final standard, and is the reason
why your example shows a legal result. Legal results from this
example are
200 200 with evaluation order p=&x p=&y push(*p) push(*p)
100 100 with evaluation order p=&y p=&x push(*p) push(*p)
100 200 with evaluation order p=&x push(*p) p=&y push(*p)
200 100 with evaluation order p=&y push(*p) p=&x push(*p)
--
Steve Clamage, TauMetric Corp, steve at taumet.com
More information about the Comp.std.c
mailing list