Article title: a list of features of Linux kernel code in Cainiao Park. 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.
1. Indent
The length of 8 characters is set to the indent length. This makes your code easier to read and reminds you not to go too deep.
2. Disconnect long lines and long strings
Remember that our code will be read by terminals with only 24 characters on the screen.
3. Place braces
In this regard, we follow the style of Kernighan and Ritchie, the ancestor of C programmers.
If (x is true ){
We do y
}
Do {
Body of do-loop
} While (condition );
If (x = y ){
..
} Else if (x> y ){
...
} Else {
....
}
This is an exception when defining a function.
Int function (int x)
{
Body of function
}
Another benefit of using this method is space saving. We do not need to occupy one row of space for a single bracket. we need to know that some people will use terminals with small screens to watch the code, such as PDA users.
4. Naming rules
Make sure that the global variables or functions use descriptive names. Local functions are named in the scaling mode.
The Hungarian naming convention is not recommended.
5. Function
A recommended function style is short and concise, and should not exceed X 24. If your function is very long, try to disconnect it so that some of its functions are placed in other functions. If you have obvious performance requirements, you can set the split function to inline.
6. Macro, enumeration
It is recommended that all values be in uppercase, except for macro functions.
7. Do not abuse inline
The principle of the inline function is that this function does not exceed three lines of code. The exception is that there are constants in the function parameters that can be determined during compilation. you know that because of this constant, the compiler can optimize it to reduce the code of the function.