Difference between revisions of "C Coding Standard"
Peter gummer (Talk | contribs) m (→Language consideration) |
|||
Line 3: | Line 3: | ||
==Language consideration== | ==Language consideration== | ||
* Avoid using assignment inside an expression. | * Avoid using assignment inside an expression. | ||
− | * Never use '''goto''' | + | * Never use '''goto'''. |
− | * Never use '''return''' if this is not the last | + | * Never use '''return''' if this is not the last instruction of a routine. |
− | * Use '''break''' only to separate branches of a switch statement | + | * Use '''break''' only to separate branches of a switch statement. |
==Style== | ==Style== |
Revision as of 14:24, 22 July 2009
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.
Style
- Always use curly braces, even when there is only one instruction. Instead of
if (a) do_something();
write
if (a) { do_something(); }
- Place opening brace at the same line as the condition as in
while (expr) { ... } for (;;) { ... }
unless the expression is very long as in
if (very_long_expression) { ... }
- Surround else with braces as in
if (expr) { ... } else { ... }