What are sequence points, and how do they relate to undefined behavior?

C++98 and C++03 This answer is for the older versions of the C++ standard. The C++11 and C++14 versions of the standard do not formally contain ‘sequence points’; operations are ‘sequenced before’ or ‘unsequenced’ or ‘indeterminately sequenced’ instead. The net effect is essentially the same, but the terminology is different. Disclaimer : Okay. This answer …

Read more

Undefined behavior and sequence points reloaded

It looks like the code i.operator+=(i.operator ++()); Works perfectly fine with regards to sequence points. Section 1.9.17 of the C++ ISO standard says this about sequence points and function evaluation: When calling a function (whether or not the function is inline), there is a sequence point after the evaluation of all function arguments (if any) …

Read more

Why are these constructs using pre and post-increment undefined behavior?

C has the concept of undefined behavior, i.e. some language constructs are syntactically valid but you can’t predict the behavior when the code is run. As far as I know, the standard doesn’t explicitly say why the concept of undefined behavior exists. In my mind, it’s simply because the language designers wanted there to be …

Read more

Undefined behavior and sequence points

C++98 and C++03 This answer is for the older versions of the C++ standard. The C++11 and C++14 versions of the standard do not formally contain ‘sequence points’; operations are ‘sequenced before’ or ‘unsequenced’ or ‘indeterminately sequenced’ instead. The net effect is essentially the same, but the terminology is different. Disclaimer : Okay. This answer …

Read more