Article View: comp.std.c
Article #2567Function Argument Evaluation
From: John Polstra
Date: Mon, 18 Mar 1991 19:29
Date: Mon, 18 Mar 1991 19:29
37 lines
1531 bytes
1531 bytes
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@uunet.uu.net
Polstra & Co., Inc. ...!uunet!polstra!jdp
Seattle, Washington USA (206) 932-6482
"Self-knowledge is always bad news." -- John Barth
Technical Details
Message-ID:
<7621@polstra.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!voder!pyramid!leadsv!practic!polstra!jdpShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!voder!pyramid!leadsv!practic!polstra!jdp From: jdp@polstra.UUCP (John Polstra) Newsgroups: comp.std.c Subject: Function Argument Evaluation Message-ID: <7621@polstra.UUCP> Date: 18 Mar 91 19:29:25 GMT Organization: Polstra & Co., Inc., Seattle Lines: 37