Page 230 - The Art of Designing Embedded Systems
P. 230
A Firmware Standards Manual 2 1 7
Put a space after each comma in argument lists and after the semi-
colons separating expressions in a for statement.
Put a space before and after every binary operator (like +, -, etc.).
Never put a space between a unary operator and its operand (e.g., unary
minus).
Put a space before and after pointer variants (star, ampersand) in de-
clarations. Precede pointer variants with a space, but have no following
space, in expressions.
Indent C code in increments of two spaces. That is, every indent level
is two, four, six, etc. spaces. Indent with spaces, never tabs.
Always place the # in a preprocessor directive in column I.
Never nest IF statements more than two deep; deep nesting quickly
becomes incomprehensible. It’s better to call a function, or even better to
replace complex IFs with a SWITCH statement.
Place braces so the opening brace is the last thing on the line, and
place the closing brace first, like:
if (result > a-to-d) {
do a bunch of stuff
1
Note that the closing brace is on a line of its own. except when it is
followed by a continuation of the same statement, such as:
do I
body of the loop
} while (condition);
When an i f -else statement is nested in another i f statement, al-
ways put braces around the i f -el se to make the scope of the first i f
clear.
When splitting a line of code, indent the second line like this:
function(f1oat argl, int arg2, long arg3,
int arg4)
if (long-variable-name && constant-of-some-sort ==
2
&& another-condition)

