struct Flat {
int a1;
int a2;
}
// a hierarchical struct which containing a struct attribute
struct NonFlat {
Flat b1;
int b2;
}
Flat f1, f2;
memcmp (&f1, &f2, sizeof f1)
在我的编译器中,它可以工作,意思是
f1.a1 == f2.a1, f1.a2 == f2.a2 <=> memcmp (f1, f2) == 0;
NonFlat n1, n2;
memcmp (&n1, &n2, sizeof n1) // does it also work for non-flat structs, considering the padding?
我认为它也应该适用于 NonFlat 结构。但是,在我的编译器中,对于非平面结构,即使成员属性相等,memcmp 的结果也表明它们是不同的。