From: "Andris K," < XXXX@XXXXX.COM >
Date: Mon, 11 Jan 2010 18:26:01 -0600 (CST)
Message-ID: < XXXX@XXXXX.COM >
The above expression statement contains two sequence points:
1) C89 188.8.131.52 Function calls:
"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."
2) C89 6.6 Statements
"A full expression is an expression that is not part of another
expression. Each of the following is a full expression: [...] the
expression in an expression statement [...] The end of a full
expression is a sequence point."
The program contains undefined behavior.
C89 6.3 Expressions
"Between the previous and next sequence point an object shall have
its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored."
The second phrase is violated. Consider the following (partial) order of
a) sequence point 1 is reached,
b) pcptr is evaluated on the left hand side of the assignment operator,
c) function_A() is called,
d) sequence point 2 is reached (the semicolon at the end of line).
In step b, "pcptr" is evaluated for a different purpose than establishing
its next stored value (which happens in step c). Therefore, the compiler
sees no functional dependency between those steps, and since no sequence
point intervenes either, the compiler can order those steps (even
parallelize them) as it likes.
I don't think so.
It's not astonishing in my opinion, they are free to. The program must be
fixed, for example:
code = function_A();
/* modification of pcptr complete here */
pcptr->code = code;
But rather eliminate the global variable pcptr and/or rewrite
(I hope I didn't botch this up too much.)
comp.lang.c.moderated - moderation address: XXXX@XXXXX.COM -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.