babon babon - 1 year ago 100
C Question

Increment operators and "undefined behaviour"

As mentioned here, the C standard states:

Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be accessed only to determine the
value to be stored.

But, this link says that
a = ++b + ++c;
is undefined. Could someone please explain why this is undefined behaviour?

Answer Source

Provided the objects involved (a, b and c) in the expression a = ++b + ++c; are distinct, that expression is well-defined.

Perhaps, the author meant to use the same variable twice such as a = ++b + ++b;. I can only speculate. But there's no undefinedness in the given expression.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download