#include <stdio.h>
#define BYTE1 __attribute__((packed, aligned(1))) //aligned(1):1字节对齐
typedef struct //默认4字节对齐
{
int num1;
char ch1;
int num2;
char ch2;
}Str_four;
typedef struct
{
int num1;
char ch1;
int num2;
char ch2;
}BYTE1 Str_one;
int main()
{
printf("str_four: %ld\n", sizeof(Str_four));
printf("str_one: %ld\n", sizeof(Str_one));
}
结果如下:
str_four: 16
str_one: 10