一、结构体内存占用
这个对齐和编译器有关系。
// 内存对齐
typedef struct
{
int x;
float y;
char c;
}TEST;
// 字节对齐
#pragma pack(push) // 将当前pack设置压栈保存
#pragma pack(1)// 必须在结构体定义之前使用
typedef struct
{
int x;
float y;
char c;
}TEST_PACKED;
#pragma pack(pop) // 恢复先前的pack设置
字节对齐在keil里面使用另外一种方式
typedef __packed struct
{
int x;
float y;
char c;
}TEST_PACKED;
这个对齐和编译器有关系。
// 内存对齐
typedef struct
{
int x;
float y;
char c;
}TEST;
// 字节对齐
#pragma pack(push) // 将当前pack设置压栈保存
#pragma pack(1)// 必须在结构体定义之前使用
typedef struct
{
int x;
float y;
char c;
}TEST_PACKED;
#pragma pack(pop) // 恢复先前的pack设置
字节对齐在keil里面使用另外一种方式
typedef __packed struct
{
int x;
float y;
char c;
}TEST_PACKED;




