A one word change to the C standard to make undefined behavior sane again
The author concedes that he isn&#x27;t a compiler engineer, but doesn&#x27;t seem to think that perhaps compiler engineers have good reason for having their compilers generate code that behaves bizarrely if there&#x27;s undefined behavior.<p>There is, of course: performance.<p>If you want a compiler that generates code which behaves intuitively even under UB, that requirement is at odds with compiler optimisation. Compiler optimisation generally means doing strange and unexpected things to your code, and the reason C has undefined behaviour in the first place (unlike, say, Java) is to maximally enable compiler optimisation.<p>In other words, C values performance over safety, and that&#x27;s part of the point.<p>If you want to catch undefined behaviour at runtime and treat it as an error, the tooling for doing that is better than ever: Clang&#x27;s &#x27;UBSan&#x27;, for instance.<p><i>Edit</i><p>Aside: I have a personal favourite &#x27;incident&#x27; pertaining to exactly this tension (between performance and intuitive behavior). Torvalds vents his frustrations on the GCC mailing list, regarding legal-but-counterintuitive behaviour of code generated for the Alpha architecture: <a href="https:&#x2F;&#x2F;gcc.gnu.org&#x2F;ml&#x2F;gcc&#x2F;2012-02&#x2F;msg00038.html" rel="nofollow">https:&#x2F;&#x2F;gcc.gnu.org&#x2F;ml&#x2F;gcc&#x2F;2012-02&#x2F;msg00038.html</a>