标题:linux 内核源代码风格
来源:https://www.kernel.org/doc/html/v4.13/translations/zh_CN/coding-style.html
正文:
1. 缩进:等于制表符大小,8 字符
2. 行长度限制:80 列。但对用户可见字符串例外,如 prink
3. 大括号使用:
if (x is True){
we do y;
}
函数例外:
int function(int x)
{
body of function;
}
如果大括号后面是语句的剩余部分:
do {
body of do-loop
}while(condition)
if (x == y) {
something;
}else if ( x > y) {
something;
}else{
something;
}
4. 不使用大括号:单独语句
if (condition)
action();
if (condition):
do_this();
else
do_that()
但是整个语句应保持一致性
if (condition) {
do_this();
do_that();
} else {
otherwise();
}
5. 空格
加空格的关键字
if () switch () case () for () do () while ()
不加空格的关键字
评论0