Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example, the order of evaluation of the operands to + is undefined.

Code Block
bgColor#FFcccc
a = i + b[++i];

If i was equal to 0 before the statement, this statement may result in the following outcome:

...

These examples are independent of the order of evaluation of the operands and can only be interpreted in one way.

Code Block
bgColor#ccccff
++i;
a = i + b[i];

Or alternatively:

...

There is no ordering of subexpressions implied by the assignment operator, so the behavior of these statements is undefined.

Code Block
bgColor#FFcccc
i = ++i + 1;
a[i++] = i;

Compliant Solution

These statements are allowed by the standard.

Code Block
bgColor#ccccff
i = i + 1;
a[i] = i;

Non-Compliant Code Example

The order of evaluation of arguments to a function is undefined.

Code Block
bgColorFFcccc
func(i++, i++);

Compliant Solution

This solution is appropriate when the programmer intends for both arguments to func() to be equivalent.

Code Block
bgColor#ccccff
i++;
func(i, i);

This solution is appropriate when the programmer intends for the second argument to be one greater than the first.

...