8
鑑於這些結構:C有效/符合工會的這種使用?
typedef struct {
//[...]
} StructA;
typedef struct {
StructA a;
//[...]
} StructB;
typedef union {
StructA a;
StructB b;
} Union;
低於等同,而不是不確定的兩種接入方式?
Union u;
memcpy(&u.b, /*...*/); //Pretend I populated StructB here
u.a; // Method 1
u.b.a; // Method 2
請注意StructA碰巧是StructB的第一個成員。
我在代碼庫中發現了這個問題,我只是想知道它是標準還是有任何對齊問題。