-
Indent using four (4) spaces. Do not use tabs for indentation.
-
Use no space between
*and the variable name in pointer expressions (int *foo). -
Use space between keywords and parentheses; e.g.,
if (condition). -
Put the opening brace of a function implementation on the line after the function’s return type, name, and argument list.
-
Use
#pragma oncein addition to include guargs in header files to avoid duplicated includes.
-
Use
snake_caseto name a multi-word variable or type. -
Use
UPPER_SNAKE_CASEfor, and only for, preprocessor symbols and values of enumeration type. -
Use typedef to create aliases for all struct types.
-
The names of type aliases should always end in
_t. -
Function pointer type aliases should always end in
_fn. -
Do not alias pointer types with
typedef; we keep them explicit. -
Name boolean variables with a verb phrase including a verb like
is_,has_, orwant_so that the intent of the variable is clear in expressions and conditionals. -
Avoid magic numbers; define meaningful constants. Prefer C language symbols over preprocessor symbols, because the former are visible in a symbolic debugger like gdb.