struct student
{
int a;
char b;
char f;
//short c;
float d;
//char e;
{
int a;
char b;
char f;
//short c;
float d;
//char e;
}stu;
sizeof(stu) = 12;
struct student
{
int a;
char b;
//char f;
//short c;
float d;
char e;
}stu;
sizeof(stu) = 16;__attribute__((aligned(n)))指定按n字节对齐;
本文探讨了C语言中结构体成员对齐的问题,并通过两个示例展示了不同成员排列顺序如何影响结构体的整体大小。此外,还介绍了如何使用__attribute__((aligned(n)))来指定结构体成员的对齐方式。
2956

被折叠的 条评论
为什么被折叠?



