Key Words
None
__attribute__ / packed
取消对齐的方法
#include<stdio.h>
#pragma pack (1)
struct stu{
char sex;
int length;
char name[10];
};
#pragma pack ()
---------------------------------
struct stu{
char sex;
int length;
char name[10];
}__attribute__ ((packed));
int main(){
struct stu my_stu;
printf("%x\n%x\n%x\nsize:%d\n", &(my_stu.sex), &(my_stu.length), &(my_stu.name), sizeof(my_stu));
return 0;
}探究默认对齐方式
什么时候需要设置对齐?
字节对齐有什么作用?
static
Reference
Last updated
