C Programming Guidelines
This is a suggested set of guidelines to follow when writing C code. It is based on my own experience as well as the influential "The Power of 10: Rules for Developing Safety-Critical Code".
- All control flow constructs must have braces
- Braces of control flow constructs go on their own lines
- 1 Avoid complex flow constructs, such as goto, setjmp/longjmp, and recursion.
- 1 All loops must have fixed bounds to avoid runaway code.
- 1 Avoid heap memory allocation after initialization.
- Minimize cyclomatic complexity and length of function bodies.
- Utilize design by contract on all public APIs and internal functions that are mission critical
- Restrict the scope of data to the smallest possible.
- Do not utilize function-scoped static variables.
- Check the return value of all non-void functions, or cast to void to indicate the return value is unused.
- Use the preprocessor sparingly.
- Limit pointer use to a single dereference, and do not use function pointers.
- Compile with all possible warnings active and warnings treated as errors.
- Use a single return statement per function.