Search code examples
cstatic-analysisdynamic-analysis

What are the go-to tools for finding errors in C code?


It might be either static or dynamic analysis, preferably free.


Solution

    • cppcheck checks both C and C++ code and finds many errors.

    • Valgrind is a tool for runtime analysis, but I mention it anyway. It is extremely useful for tracking memory errors like uninitialized usage or leaks.

    • Also, activate ALL warnings your compiler has (GCC and clang: -Wall -Wpedantic -Wextra), which often reveals useful info.

    • Note: clang sometimes generates much better warnings/errors than GCC

    • To find logic errors, however, testing is required. Testing is required anyway, something that is not tested is per definition broken, as you cannot assume it works.
      Wikipedia has a list of C unit testing software.