我是内核编程的新手,所以我想了解哪种编码风格更容易被接受。例如,在错误处理的情况下,以下哪个更好?
这个:
/* some stuff */
if(error) {
/* error handling */
return -(errorcode);
}
/* normal actions */
或者这个:
/* some stuff */
if(!error) {
/* normal actions */
} else {
/* error handling */
return -(errorcode);
}
我在哪里可以找到关于内核编码标准的文档?
最佳答案
Linux 内核有一个编码风格指南:
https://www.kernel.org/doc/Documentation/process/coding-style.rst
关于你的例子,我个人更喜欢第一种风格。使用第二种样式,您将很快违反此 Linux 内核样式规则(内核样式有 8 个字符的缩进):
if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
从上到下(相对于水平方向)编写代码有时被称为duffing。我可以向您推荐有关该主题的优秀读物:
关于c - Linux内核编码风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12772253/