The original ANSI C standard, C89, introduced the concept of “undefined behavior,” from handling uninitialized variables to arithmetic overflow and null pointer usage, all prioritizing performance over correctness. With modern compilers treating undefined behavior differently, unexpected bugs arise, leading to broken programs. Examples include uninitialized variables in C and C++ optimizing away loops, signed integer overflow rendering incorrect results, infinite loops being optimized out, and std::sort corrupting memory with invalid comparison functions. Despite the debate to define signed integer overflow for correctness, performance remains the top priority in C++ compilers, highlighting the language’s preference for speed over accuracy.
https://research.swtch.com/ub