|
|
|
|
|
by coldgrnd
5052 days ago
|
|
Most of what I learned about C++ I got from books, blogs and some great C++ guys (mostly from the boost community). I have to admit I did not read the standard at all. could you give an example of a case where you hit undefined behavior since I hardly seem to recall a case where that bit me in the past? (I'm mostly working on embedded systems (PPC & ARM)) The cases that come to my mind for C++ all involve initialization... |
|
The two most commonly cited piece of undefined behavior is modifying a variable twice in one sequence point. The standard says:
This code snippet invokes undefined behavior: because b is modified twice within one sequence point. More information here http://stackoverflow.com/questions/4176328/undefined-behavio...-----
For more real world examples of where undefined behavior may bite you in the ass in C++, take a look at Washu's simple C++ quiz. It's only four questions: http://www.scapecode.com/2011/05/a-simple-c-quiz/
Take a moment to answer the questions before looking at the answers.
Once you've done that, here are three more quizzes by the same guy - these ones are about OOP in C++, so may be much more relevant to your question: http://www.scapecode.com/2011/05/c-quiz-2/ and http://www.scapecode.com/2011/05/c-quiz-3/ and http://www.scapecode.com/2011/05/c-quiz-4/