Deep Learning about Linux and Linux kernel programming style

Source: Internet
Author: User
Learn more about Linux, Linux kernel programming style-general Linux technology-Linux programming and kernel information. This short document describes the recommended programming style in Linux kernel programming. Programming style is very personal. I don't want to impose my opinion on anyone, but this is what I observe in the code that I must maintain, I also recommend that other parts of the Code comply with it. Please give at least some considerations here.

First of all, I suggest you print a GNU code style, instead of reading it, but burning it. This is a good gesture.

The Linux kernel programming style is as follows:

Chapter 1: Indent

The Tab character (tabs) occupies 8 characters, so the indentation is also 8 characters. Some adopt a four-character (or even two-character) indent for the cult movement, which is no different from setting PI (circumference rate) to 3.

Cause: indent is used to clearly identify the starting point of a control block. Especially after you stare at the screen for 20 hours, you will experience the benefits of longer indentation.

At present, some people propose that 8-character indentation will make the code too biased towards the right, and it is difficult to read when the 80-character terminal is used. The answer is that if you need more than three layers of indentation, you are finished and you should change your program.

In short, 8-character Indentation makes it easier to read the code and warn when your indentation level is too deep. Pay attention to such warnings. I cannot agree with this. The four-character indentation does have its advantages. The indentation is too much, but it looks tired. And sometimes only two layers of nesting will make the code very long.

Chapter 2: brackets

The issue of brackets is often raised in the C programming style. Unlike the indentation size, there are not many technical reasons for choosing the angle brackets, but more of them are personal preferences. For example, the disciples of Kernighan and Ritchie put the left brackets at the end of a row and put the right brackets at the beginning of a row, as shown in the following figure:
CODE: if (x is true ){
We do y
}
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.