Function Argument Evaluation
John Polstra
jdp at polstra.UUCP
Tue Mar 19 05:29:25 AEST 1991
Consider the following program:
#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.
If I understand correctly, it would be valid to evaluate in this order:
"%d %d\n" /* First argument */
(p = &x) /* Subexpression within second argument */
(p = &y) /* Subexpression within third argument */
*p /* Second argument */
*p /* Third argument */
and the resulting output would be "200 200".
Could somebody please support or refute (with accompanying rationale) my
reasoning?
--
John Polstra polstra!jdp at uunet.uu.net
Polstra & Co., Inc. ...!uunet!polstra!jdp
Seattle, Washington USA (206) 932-6482
"Self-knowledge is always bad news." -- John Barth
More information about the Comp.std.c
mailing list