The following types of usage are often seen in the Linux kernel source code:
static struct platform_device androidusb_device = { .name = "android_usb", .id = -1, .dev = { .platform_data = &android_usb_pdata, }, };
Here, platform_device is a defined structure (defined in kernel/include/linux/platform_device.h). androidusb_device is a specific device, and the content in the brackets is structure initialization.
Platform_device is defined as follows:
struct platform_device { const char * name; int id; struct device dev; u32 num_resources; struct resource* resource; const struct platform_device_id*id_entry; /* arch specific additions */ struct pdev_archdataarchdata; };
I searched for the introduction to struct on the Internet. Most of them are just a simple introduction. I have a good article, and I have extracted some of them and posted them here.
Struct is an important ADT in C. However, in general C books, only the definition, sequence initialization, and bit fields of struct are introduced. This article lists the knowledge points that I have used and seen and shares them with you. Http://hi.baidu.com/cjzswust/blog/item/d1d2191f5ddc481541341711.html)
To facilitate the subsequent introduction, first define a struct type:
struct User { int id; //id char name[100]; //user name char *home; //home directory int passwd; //password };
There are three initialization methods for struct data: Order, disorder of C style and C ++ style.
1) Order
This method is very common and has been introduced in general books that introduce C. Sequential Initialization is characterized by the sequence defined by members, which is initialized one by one from the beginning to the end. Only some members are allowed to be initialized. No uninitialized members are allowed before the initialized members.
Eg: struct User oneUser = {10, "Lucy", "/home/Lucy"}; after initialization, the values of each oneUser member are oneUser. id = 10; oneUser. name = "Lucy"; oneUser. home = "/home/Lucy"; oneUser. passwd = 0;
2) disorder (C style)
The sequential defect is that it must be initialized one by one in the order defined by Members, and cannot be separated. The out-of-order method solves this problem, because this method is based on the member name.
eg: struct User oneUser = { .name = "Lucy", .id = 10, .home = "/home/Lucy" };
3) disordered (C ++ style)
The unordered Initialization Method of the C ++ style is the same as that of the C style, but it is more commonly used in C ++ code.
eg: struct User oneUser = { name:"Lucy", id:10, home:"/home/Lucy" };
In either way, only some members can be initialized. The default value of uninitialized members is 0 (the default value of pointer type members is NULL ). Two out-of-order initialization methods can be used in C code or C ++ code.