Undefined behavior in C and C++
February 3, 2024
Working in C or C++ requires some awareness of undefined behavior: what it is, what its effects are, and how to avoid tripping over it. For simplicity, I will just talk about C, but everything in this article also applies to C++ except where otherwise noted.
What is undefined behavior?
What behaviors are undefined?
Dereferencing a bad pointer
Uninitialized data
Signed integer overflow
Bit shifting
Aliasing
Why?
It's not about unusual hardware
It is about optimization
Except when...
Read more at lumagraph.ie