C Coding Standard: Difference between revisions

From EiffelStudio: an EiffelSoftware project
Jump to navigation Jump to search
Manus (talk | contribs)
Added C standard guidelines
Manus (talk | contribs)
No edit summary
Line 11: Line 11:
* Place opening brace at the same line as the condition as in
* Place opening brace at the same line as the condition as in
<c>while (expr) {
<c>while (expr) {
...
}
}
for (;;) {
for (;;) {
...
}
}
</c>
</c>

Revision as of 06:13, 21 July 2009


  • 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 {
	...
}
  • Avoid using assignment inside an expression.