Not specific code writing practices. Please also include reasoning.
My start:
- use
GCCorClang- gcc because it is unchallenged in the amount of static checking it can do (both against standards and general errors)
- clang cause it has such pretty and meaningful error messages
- when compiling C code using GCC use
-Wall -Wextra -Wwrite-strings -Werror- in 99,99% the warning is a valid error
- when compiling C++ code using GCC use
-Wall -Wextra -Weffc++ -Werror- you could skip
-Weffc++(cause it can be confusing)
- you could skip
- always code against a standard C (C89, C99), C++ (C++98, C++0x)
- while compilers change, standards don't, coding against a standard gives at least some level of assurance that the code will also compile in the next version of the compiler or even a different compiler/platform
- make sure that the compiler checks your code against standard (
-std=c99 -pedanticfor C99,-std=ansi -pedanticfor C++98 in GCC)- cause automatic checking always good
- use
valgrindor a similar tool to check for runtime errors (memory, threads, ...)- free bug catching
- never duplicate functionality of the standard libraries (if there is a bug in your compiler, make a temporary patch, wrapper, ...)
- there is no chance that your code will be better then the code maintained by hundreds of people and tested by tenths of thousands
- make sure that you actually fix all bugs that are reported by automatic tools (GCC, valgrind)
- the errors might not cause your program to crash now, but they will
- never follow recommendations that include "never use feature X"
- such recommendations are usually outdated, exaggerated or oversimplified