联合体中嵌套结构体定义

 1 /* 第一种方法 */
 2 typedef union
 3 {
 4     struct VEHICLE_s
 5     {
 6         TERMINAL_DATA_s sTerminal_Obj;
 7         GPS_DATA_s sGps_Obj;
 8         TMPS_DATA_s sTmps_Obj;
 9         POSE_DATA_s sPose_Obj;
10         OBD_DATA_s sObd_Obj;    
11     }Vehicle_Obj;    
12     uint8_t Vehicle_Bytes[sizeof(struct VEHICLE_s)];
13 }VEHICLE_MONIT_u;
14 
15 
16 
17 /*  第二种方法 */
18 typedef struct 
19 {
20     TERMINAL_DATA_s sTerminal_Obj;
21     GPS_DATA_s sGps_Obj;
22     TMPS_DATA_s sTmps_Obj;
23     POSE_DATA_s sPose_Obj;
24     OBD_DATA_s sObd_Obj;    
25 }VEHICLE_s; 
26 
27 typedef union
28 {
29     VEHICLE_s Vehicle_Obj;    
30     uint8_t Vehicle_Bytes[sizeof(struct VEHICLE_s)];    /* 第1种表示 */
31     uint8_t Vehicle_Bytes[sizeof(VEHICLE_s)];           /* 第2种表示 */  
32 }VEHICLE_MONIT_u;
33 
34 
35 
36 /* 第三种方法(失败) */
37 typedef struct 
38 {
39     TERMINAL_DATA_s sTerminal_Obj;
40     GPS_DATA_s sGps_Obj;
41     TMPS_DATA_s sTmps_Obj;
42     POSE_DATA_s sPose_Obj;
43     OBD_DATA_s sObd_Obj;    
44 }VEHICLE_s; 
45 
46 typedef union
47 {
48     VEHICLE_s Vehicle_Obj;    
49     uint8_t Vehicle_Bytes[sizeof(Vehicle_Obj)];  
50 }VEHICLE_MONIT_u;

 

posted @ 2018-01-02 13:45  壹点灵异  阅读(6541)  评论(6编辑  收藏  举报