Yes, it is undefined. You're modifying the same variable twice between sequence points.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.
Now there is such a notion as indeterminately sequenced evaluations in the C++ Standard.Are not the two increments indeterminately sequenced and the full expression well formed?
From §1.9 P15, it would appear neither example is well defined.
One tip to avoid confusion is to replace the operator by a function call:
This operatoroperator+(++i, ++i); // no defined order therefore the behavior is undefinedhas defined behaviour because the both side effects shall be applied before calling the operator.
On Tue, Aug 6, 2013 at 1:19 PM, Vlad from Moscow <vlad....@mail.ru> wrote:
This operator
operator+(++i, ++i); // no defined order therefore the behavior is undefined
r
has defined behaviour because the both side effects shall be applied before calling the operator.
No, given an initial value of X for i, it is undefined whether that calls `operator+(X+1,X+2)` or `operator+(X+2,X+1)`
Given an initial value of X the compiler shall apply side effect to lvalue X after the first ++X and after the second ++X and then use this updated value of the lvalue to pass arguments to function.
This is totally the same asint s = ++i + ++i;and does not depend on the order of calculating subexpression.After the first decrement the side effect has to be applied. As lvalue was changed the new value of the lvalue has to be reread (or read) in the second expression. It is the meaning of applying of side effects. Then again the second expression is decremented and its side effect shall be applied before operator -. The operator shall use the last value of the lvaule.
This is totally the same asint s = ++i + ++i;and does not depend on the order of calculating subexpression.
--
This is totally the same asint s = ++i + ++i;and does not depend on the order of calculating subexpression.After the first decrement the side effect has to be applied. As lvalue was changed the new value of the lvalue has to be reread (or read) in the second expression. It is the meaning of applying of side effects. Then again the second expression is decremented and its side effect shall be applied before operator -. The operator shall use the last value of the lvaule.