I know that writing something like
++a = a++;
Is not only unreadable but also violates the c/c++ sequence points.
Where do these limitations come from? How can one see those ‘problems’ before finding them as bugs?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically there is a C++03 sequence point between each statement. For more information see the SO C++ FAQ. For even more information do consult the C++ standard, and keep in mind that in the C++11 standard sequence points were replaced with sequenced before and sequenced after relations.
To avoid problems, simply don’t try to be too clever about doing a lot in each expression.
Don’t try to do the compiler’s job: leave that to the compiler. Your job is to write code that other humans can easily understand, i.e. clear code. Multiple updates and needless use of operators with side effects is not compatible with that.
Tip: sprinkle
constjust about everywhere possible.That constrains the possible state changes that a reader must take into account.