嵌套结构体初始化的几种方式

# 结构体定义

structA define

1 typedef struct
2 {
3     char a;
4     int b;
5     float c;
6 }struct_A_s;

structB define

1 typedef struct
2 {
3     char a;
4     int b;
5     struct_A_s obj;
6     float c;
7 }struct_B_s;

 

# 结构体初始化

NO.1  /* use member access */

1 struct_B_s sObj =
2 {
3     10,
4     1000,
5     .obj.a    =10,  
6     .obj.b    =1000, 
7     .obj.c    =0.1,
8     9.99        
9 }

 

NO.2  /* use '{}' direction access */

1 struct_B_s sObj =
 2 {
 3    10,
 4    1000,
 5 
 6    {
 7        .a    =10,  
 8        .b    =1000, 
 9        .c    =0.1, 
10    },
11     
12    9.99                
13 }    

 

 

NO.x

结合结构体初始化的几种方式,可组合出其他几种方式

 

posted @ 2018-04-25 16:59  壹点灵异  阅读(5916)  评论(0编辑  收藏  举报