1. Tabs are 8 characters, and thus indentations are also 8 characters.
2. If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
3. "Switch" and its subordinate "case" labels in the same column instead of "double-indenting" the "case" labels.
E.g.: switch (suffix) {
case 'g' :
mem <<= 30;
case 'm' :
mem <<= 20;
default :
break;
4. Don't put multiple statements on a single line unless you have something to hide.
5. Don't put multiple assignments on a single line either. Avoid tricky expressions.
6. Outside of comments, documentation and except in Kconfig, spaces are never used for indentation.
7. Don't leave whitespace at the end of lines
8. The limit on the length of lines is 80 columns
9. do {
body of do-loop
} while (condition);
10. if (x == y) {
} else if (x > y) {
...
} else {
....
}
//this brace-placement also minimizes the number of empty (or almost empty) lines
11. Do not unnecessarily use braces where a single statement will do.
if (condition)
do_this();
else
do_that();
12. This does not apply if only one branch of a conditional statement is a single statement;
if (condition) {
do_this();
do_that();
} else {
otherwise();
}
13. use a space after if, switch, case, for, do, while. Do not add spaces around (inside) parenthesized expressions. "s = sizeof( struct file );" is bad.
14. Use one space around (on each side of) most binary and ternary operators,such as any of these: = + - < > * / % | & ^ <= >= == != ? :