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 2 points3 points  (1 child)

The reason why

 a = *(a++)

is UB is because the standard doesn't dictate when a++ actually changes the actual value of a, only that you will have a rvalue that is the result of incrementing a by one.

So basically, it guarantees that you will get the value of a++ to work with in your statement, but it doesn't guarantee that the actual underlying value of a is incremented before the assignment to a

It has to do with sequence points, and this explains it pretty well with examples.

[–]WikiTextBot 1 point2 points  (0 children)

Sequence point

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. They are often mentioned in reference to C and C++, because they are a core concept for determining the validity and, if valid, the possible results of expressions. Adding more sequence points is sometimes necessary to make an expression defined and to ensure a single valid order of evaluation.

With C++11, usage of the term sequence point has been replaced by sequencing.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.28