Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment operators and "undefined behaviour"

As mentioned in the comp.lang.c FAQ, 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 (now deleted) article says that a = ++b + ++c; is undefined. Could someone please explain why this is undefined behaviour?

like image 389
babon Avatar asked Aug 15 '16 16:08

babon


1 Answers

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.

like image 96
P.P Avatar answered Oct 05 '22 07:10

P.P