Linux under C struct initialization

Source: Internet
Author: User

The original address is here:

I only wrote the main introduction and the code here.

Sequential initialization

In textbooks, C language structure initialization is in the order of the way, there is no way to deal with the chaotic sequence. The sequential initialization of the struct must be in accordance with the order of the members, indispensable, if the structure is larger, prone to errors, and the form is not intuitive, you can not see the values of each struct data member.

form like; data_t data={10,20}

Random sequence Initialization

Chaotic initialization is a new addition to the C99 standard, a more intuitive way to initialize. In the case of sequential initialization, the sequence initialization is like its name, the members can be initialized in order, and only some members can be initialized, and the extensibility is better. The Linux kernel initializes the struct in this way.

There are two ways to initialize a random sequence, one is to use a dot (.) symbol, and one is to use a colon (:). Mode 1 is the C99 standard, and Mode 2 is the extension of GCC, and it is strongly recommended to use the first method.

Linux under C struct initialization

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: 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.