This approach is allowed by the C language standard, and perhaps many others. In the C spec, it is explicitly stated that this is allowed. But it makes no distinction on whether the operands have side effects or not, thus the same code can (and often does) produce different results depending on the compiler used. The language spec defines sequence points and requires that all assignments be made and side-effects resolved before proceeding beyond the sequence point. But the order in which things happen between sequence points is unspecified -- it does not even have to be specified by the implementation.The ordering operands is to make the order of the side effects predictable. For instance, if each of the operands is a function call, and the functions have side effects, then you cannot change the order in which those functions are called.
However, you can evaluate the operands, assign the results to registers or temps, then evaluate the expression from those temps in any order that produces the correct value.
But we are talking about the C# spec here and my question is whether the C# spec specifies the order of evaluation of subexpressions.
Last edited: