Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a sequence point between these assignments?

Is there a sequence point between the two assignments in the following code:

f(f(x=1,1),x=2);
like image 758
R.. GitHub STOP HELPING ICE Avatar asked Sep 09 '11 02:09

R.. GitHub STOP HELPING ICE


People also ask

What is sequence points?

A sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.

What is sequence point in c++?

Sequence point rules (until C++11) A sequence point is a point in the execution sequence where all side effects from the previous evaluations in the sequence are complete, and no side effects of the subsequent evaluations started.

Is comma a sequence point?

The comma operator has the lowest precedence of any C operator, and acts as a sequence point.

Do not depend on the order of evaluation for side effects?

Do not depend on the order of evaluation for side effects unless there is an intervening sequence point. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.


1 Answers

No there isn't. The standard is indeed ambiguous in this case.

If you want to confirm that, gcc has this really cool option -Wsequence-point and in this case it will warn you that the operation may be undefined

like image 191
Foo Bah Avatar answered Oct 30 '22 11:10

Foo Bah