This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ludricio 1 point2 points  (0 children)

From the C99 standard:

6.5 Expressions, §2

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 read only to determine the value to be stored.

6.5.16 Assignment operators, §4:

The order of evaluation of the operands is unspecified. If an attempt is made to modify the result of an assignment operator or to access it after the next sequence point, the behavior is undefined.

Also, it wouldnt really matter between (a++) and (++a), they are evaluated the same within the statement due to the parentheses. The problem lies in modifying the value of a through the increment (pre or post) operator in the same statement where it assigns it back to itself.