U
user923005
[snip]
I guess that I really cannot see what the fuss is about because I do
not seem to grasp the actual issue at hand.
See the reply by Kaz. Your examples have a point - they deal
with the reordering of the course of computations of well defined
expressions. The goal typically is to achieve greater accuracy
or more efficient code with the same end result. While this is
important and of interest, it's not the subject of discussion -
at least what I understand it to be.
What we are talking about is things like what happens between
sequence points. Tim's original example is the line
a = f(g(x),h(y));
This code could have different results depending on whether the
compiled code evaluates g(x) first or h(y) first. This could
happen in a lot of ways; I'm sure you could think of half a dozen
without much effort.
If the expression/statement is evaluated left to right this cloud
of possible results collapses to a single result. Is this
collapse a good thing; I argue that it is, Tim that it is not.
In C there are issues having to do with assignment being an
operator and with the comma operator. The pre and post increment
operators add a source of confusion. For example, consider
x[++i] = i;
One possible evaluation rule is to rule the right hand side first
and the left hand side second; another is to evaluate left to
right. The two rules give different results. Which is better?
The C standard (IIANM) just says "undefined".
Does this clarify things?
I guess that one purpose is to take examples of currently undefined
behavior and force a definition.
For example:
x[++i] = i;
would currently result in undefined behavior. I personally think that
creating a definition for an operation of this nature is not
necessarily a good thing.
x[i++] += i++ * ++i / (x[i++] + x[++i]); /* Oh joy, I can't help
but look forward to debugging things like this. */
This one is not as clear cut to me:
a = f(g(x),h(y));
I can see demanding that the commas operate both as function call
separators and as sequence points so that this would be equivalent:
q = g(x);
r = h(x);
a = f(q,r);
On the other hand, what if the the function call paramters are
expressions? In that case, I am not sure what sort of action makes
sense.
Consider:
a = f(++i, i++, ++i, i++); // now what?
I think that if we want to add a sequence to define a more exact
meaning it has to make sense generically.