Get the latest tech news
A Guide to Undefined Behavior in C and C++ (2010)
Programming languages typically make a distinction between normal program actions and erroneous actions. For Turing-complete languages we cannot reliably decide offline whether a program has the potential to execute an error; we have to just run it and see.
About a year ago, the Linux kernel started using a special GCC flag to tell the compiler to avoid optimizing away useless null-pointer checks. In the long run, unsafe programming languages will not be used by mainstream developers, but rather reserved for situations where high performance and a low resource footprint are critical. to get even more warnings Use compiler-supported dynamic checks; for example, gcc’s -ftrapv flag generates code to trap signed integer overflows Use tools like Valgrind to get additional dynamic checks When functions are “type 2” as categorized above, document their preconditions and postconditions Use assertions to verify that functions’ preconditions are postconditions actually hold Particularly in C++, use high-quality data structure libraries
Or read this on Hacker News