coding style

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: = + - < > * / % | & ^ <= >= == != ? :













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值