pep*_*ero -3 c c++ struct padding memcmp
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)
Run Code Online (Sandbox Code Playgroud)
在我的编译器中,它起作用,意思是
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?
Run Code Online (Sandbox Code Playgroud)
我认为它也适用于NonFlat结构.但是,在我的编译器中,对于非平面结构,即使成员属性相等,memcmp的结果也表明它们是不同的.
| 归档时间: |
|
| 查看次数: |
533 次 |
| 最近记录: |