General C++ quality guidelines

C++ is a tricky language to master, and it is extremely easy to write slow and/or inefficient code in it. Though nothing replaces experience and trial and error, having some background is recommended. A well written and quite comprehensive, if somewhat old, guide can be found here: http://www.agner.org/optimize/optimizing_cpp.pdf.
Furthermore, users that are not used to C++ should check out the (C++ FAQ), which answers a decent amount of interrogations that Stack Overflow would otherwise answer confusingly. Users that knew classic C++ will also find a comprehensive review of C++11.

Code quality checking tools

This page is a random assortment of ideas and tools for improving quality (detecting potential bugs etc). It doesn't include things that are run automatically (like most compiler warnings). Most things are not supported on all OSes.

Dehydra static analysis checks

ps/trunk/build/dehydra has some scripts to check for specific bugs (currently argument type-checking in (w)printf-style functions).

Valgrind

Run the tests or the game or Atlas in Valgrind, to get reports of uninitialised memory and leaks and so on. The code should run cleanly with no errors (though there may be errors reported in drivers which you need to ignore). Valgrind is really really slow, so we probably ought to have some way to record real-time inputs and play them back at Valgrind speeds, but we don't really have that now.

GCC warnings

  • -Wstrict-overflow=5 - some discussion here. Only gives useful output in optimised builds (CONFIG=Release make). Warns about cases where the compiler optimises based on assumptions that signed overflow never happens; our code should be certain those assumptions will not be violated. (There are lots of false positives so the warning isn't on by default).

Cppcheck

Last modified 4 months ago Last modified on Mar 22, 2014 6:01:18 PM