(e-mail address removed) opined:
Vladimir S. Oka wrote:
Vladimir S. Oka wrote:
On Friday 17 March 2006 04:48, (e-mail address removed) opined
(in
<
[email protected]>):
pete wrote:
(e-mail address removed) wrote:
Micah Cowan wrote:
Richard G. Riley schrieb:
On 2006-03-12, pete <
[email protected]>
wrote:
I'm coming around to thinking that 6.5 [#2] is
relevant, and that p = p->next = q
is undefined, and not just unspecified.
but
p=(p->next=q);
is fine? I hope .
No. Whether you write
a = b = c;
or
a = (b = c);
does not change anything -- apart from clarifying
your intent. You still are modifying p twice
between sequence points
Well, no he's not.
But he's reading its prior value for purposes other
than to determine the value stored, so same deal.
Look again. Reading p is necessary to evaluate p->q
= next,
No, it isn't.
The value of (p->q = next) is (next)
The value of p->q = next is next. But in order to get
the value, the assignment p->q = next must _have been
evaluated_, which needed both operands. Evaluation
includes all the actions in the Semantics paragraph,
which includes starting the side effect of storing the
value.
I think pete is right. The compiler _knows_ that the
result of (p->q = next) _will_be_ next before it even
produces any code, and can use that knowledge once it does
get to producing some.
You've fallen into the trap of arguing based on what a
compiler might be capable of. Regardless of what the
compiler knows, it's still obliged to produce code that
behaves according to how the Semantics paragraphs and
everything else in the standard says it must.
But it still does not evaluate p->q in order to assign next
to it. What is evaluated is next, and its value is /assigned/
to p->q. Next, the assignment is evaluated and assigned to p.
The assignment evaluates to next, but I don't think that
compiler is obliged to do that in any particular way.
Sorry, the compiler _is_ obliged to do the evaluation as per
the Semantics description. The Semantics paragraphs in 6.5.16
specify _both_ that the store happens and what the value is.
(Yes, the side effect of the store may happen later.) Where
in the standard is there any statement that says an expression
(_any_ expression) may yield a value _before_ it has been
evaluated?
Ok, now my head starts to spin a bit, but bear with me...
Is it right that the original problem statement was:
p = p->next = q;
Yes.
Assuming it was: `p` is not modified twice, it is read once to
get `next`, and modified once to assign value to it in the
leftmost assignment. Assigning value to `next` does not modify
`p`, right?
Now, I re-read what 6.5.16 has to say, and yes, I know examples
are not normative, but to me Example 2 (6.5.16.1p5) seems to
support the following interpretation of the above statement:
1) `q` is evaluated
2) its value is assigned to `p->next`
3) that value becomes the value of the rightmost assignment
4) that value is assigned to `p`
I read that it happens in the order I give above. Also, `p` is
modified only once (4), and read only once (2).