Why does the expression a = a + b – ( b = a ) give a sequence point warning in c++?

There is a difference between an expression being evaluated and completing its side effects.

The b = a assignment expression will be evaluated ahead of subtraction due to higher precedence of the parentheses. It will provide the value of a as the result of the evaluation. The writing of that value into b, however, may not complete until the next sequence point, which in this case is the end of the full expression. The end result of the overall expression is therefore undefined, because the subtraction may take the value of b before or after the assignment.

Leave a Comment