Linux Kernel code style

Source: Internet
Author: User
Linux Kernel code style-general Linux technology-Linux programming and kernel information. For details, refer to the following section. 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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.