C Coding Standard: Difference between revisions

From EiffelStudio: an EiffelSoftware project
Jump to navigation Jump to search
Manus (talk | contribs)
No edit summary
Manus (talk | contribs)
No edit summary
Line 1: Line 1:
[[Category:Coding Standards]]
[[Category:Coding Standards]]
{{UnderConstruction}}
{{UnderConstruction}}
==Language consideration==
* Avoid using assignment inside an expression.
* Never use '''goto'''
* Never use '''return''' if this is not the last instructions 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
*  Always use curly braces, even when there is only one instruction. Instead of
<c>if (a) do_something();
<c>if (a) do_something();
Line 33: Line 39:
}
}
</c>
</c>
* Avoid using assignment inside an expression.

Revision as of 17:01, 22 July 2009

Not Ready for Review: This Page is Under Development!

Language consideration

  • Avoid using assignment inside an expression.
  • Never use goto
  • Never use return if this is not the last instructions 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 {
	...
}