Unsequenced expressions

suggest change

The following expressions are unsequenced:

a + b;
a - b;
a * b;
a / b;
a % b;
a & b;
a | b;

In the above examples, the expression a may be evaluated before or after the expression b, b may be evaluated before a, or they may even be intermixed if they correspond to several instructions.

A similar rule holds for function calls:

f(a, b);

Here not only a and b are unsequenced (i.e. the , operator in a function call does not produce a sequence point) but also f, the expression that determines the function that is to be called.

Side effects may be applied immediately after evaluation or deferred until a later point.

Expressions like

x++ & x++;
f(x++, x++); /* the ',' in a function call is *not* the same as the comma operator */
x++ * x++;
a[i] = i++;

or

x++ & x;
f(x++, x);
x++ * x;
a[i++] = i;

have undefined behavior. A side effect on a scalar object must be sequenced relative to every other side effect on that object and relative to every value computation that uses its value. Unsequenced operands do not provide that sequencing. This is not merely an unspecified order: an unspecified order would still sequence one operand before the other.

Side effects

A side effect is a change in the state of the execution environment, such as modifying an object or calling a function that does.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents