Article title: Master style Linux operating system kernel encoding style. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This short article describes the preferred encoding style for Linux kernel. The encoding style is very personal and I will not impose my opinion on anyone. However, I have to maintain the Linux kernel code. Therefore, I would rather use the encoding style I like. Consider this at least.
First, I recommend that you print a copy of the GNU coding standard instead of reading it. It's just a symbolic gesture. Then, see:
Chapter 2: Indent
Tabs (tab) is the size of 8 characters, so the indentation should also be the size of 8 characters. Some rebellious advocates try to turn indentation into four (or even two !) It is like trying to define PI (case, circumference rate) as 3.
The idea behind indentation is to clearly define where a control block starts and where it ends. Especially after you keep staring at the screen for 20 hours, if you have a large indentation size. You will be more likely to find the benefits of indentation.
Now, some people say that the code is too right due to the 8-character indentation, and it looks uncomfortable on an 80-character terminal screen. The answer to this question is: if you have more than three levels of indentation, you are a little confused and should modify your program.
In short, the 8-character indentation makes the program easier to read, and when you hide the function too deeply, the multi-level indentation will give a very intuitive warning. Pay attention to this warning information.
Chapter 2: placing curly braces
Another idea in C program is to place curly braces. Unlike the indentation size, there is no technical reason for placing curly brackets. However, the preferred method is to put the left parenthesis at the end of the row and the right parenthesis at the beginning of the row, as shown by the prophet Brain Kernighan and Dennis Ritchie. That is:
If (x is true) {we do y}, however, there is another case where the function: the function should place the left and right brackets at the beginning of the row. That is: int function (int x) {body of function}
|
Rebellious people are everywhere. They said, this will lead... Well, inconsistency (case, the use of curly braces in the function is different from that in other cases ). However, everyone who thinks correctly knows that: (1) K & R is correct; (2) K & R is still correct. Furthermore, functions are different from other functions (you cannot hide them in C ).
Note that the row where the right parenthesis is located should not contain anything else unless it is determined by a condition. That is, "while" in the do-while statement and "else" in the if-else statement ". Like this:
Do {body of do-loop} while (condition); and: if (x = y ){..} else if (x>; y ){...} else {....}
|
Basis: K & R.
Note that the placement of curly braces reduces the number of empty rows without compromising readability. Therefore, when there cannot be many blank rows on the screen (imagine 25 rows of terminal screens), you will have more blank lines to install annotations.
[1] [2] [3] Next page