J
James Kanze
On 09/26/2010 08:09 PM, Johannes Schaub (litb) wrote:
[...]
Any expression has a unique syntax tree. In order to evaluate
one node in the tree we need to evaluate all of its children
first.
What does it mean to "evaluate" a child? The standard doesn't
say anything like this. What we do need is to "value compute"
the child nodes. There's no requirement for more.
The order by which we evaluate the subexpressions is
unspecified however. A side-effect like i++ is not visible at
the place where we evaluate the expression i++ but at the next
time we are confronted with the leaf i in the syntax tree.
When the side effect is visible depends on a lot of things.
Within a single thread, it is ordered with respect to the next
sequence point, and no more. And even then, we have to be
careful what we are talking about---the compiler may never write
the results of the incrementation, as long as the observable
behavior is the same as if it had (or there are some interthread
sequencing primitives which require it).
If the next position where we meet i in the syntax tree is
uniquely specified by the structure of the tree, we have no
ambiguity problem, otherwise we do.
There's no ambiguity. You're just confusing the guarantees
concerning the results of an expression with the order side
effects occur; the two are largely unrelated.
Let expr be an expression, then by the grammar of c++ the
expression (expr) is an expression too. There expression trees
must be different, otherwise expr and (expr) would be the same
expression. The expression tree is a subtree of (expr)
Not in any of the compilers I've seen.