I am trying to grok the comma operator. The reference says:
In a comma expression E1, E2, the expression E1 is evaluated, its result is discarded (...), and its side effects are completed before evaluation of the expression E2 begins (...).
I am unable to grok the clause - "... the expression E1 is evaluated, its result is discarded (...), and its side effects are completed before...". Specifically, what is retained and what is discarded?
For e.g., in the example from this SO answer:
int x = 0;
int y = some_number;
for(; x < y; ++x, --y)
{
// Do something which uses a converging x and y
}
When we do a ++x
, what is the 'result' (that is discarded) and what is the 'side-effect' (that is 'completed' and perhaps 'retained')? Shouldn't the result of ++x
be discarded and the value of x
remain unchanged? Working example showing incrementation of x
is here.
In other words, given a certain expression, how do I deduce if it will be evaluated and its results would be discarded, or if it is a side-effect and its results would perhaps be computed and retained?