C Coding Standard

Language consideration

  • Avoid using assignment inside an expression.
  • Never use goto.
  • Never use return if this is not the last instruction of a routine.
  • Use break only to separate branches of a switch statement.
  • A declaration
    extern void foo();
    needs to be
    extern void foo(void);
    Otherwise it is not considered a prototype (for compatability with K&R) (see bug#13870).
  • Use "%f" instead of "%lf" specifier in printf and family to print double (see bug#13872). This does not affect scanf and family.


  • Always use curly braces, even when there is only one instruction. Instead of
if (a) do_something();


if (a) {
  • Place opening brace at the same line as the condition as in
while (expr) {
for (;;) {

unless the expression is very long as in

  • Surround else with braces as in
if (expr) {
} else {