结构体在内存中存储有关问题
结构体在内存中存储问题
我有如下结构体,
typedef struct tagGuoDianHeaderStru
{
unsigned char cStartChar1;
GuoDianLenUnion unionLen1;
}GuoDianHeaderStru;
typedef union tagGuoDianLenUnion
{
unsigned short uFrameLenDomain;
struct
{
unsigned short uFrameFlag :2;
unsigned short uUserDataLen :14;
};
}GuoDianLenUnion,*LPGuoDianLenUnion;
假定cStartChar1在内存中的地址为0,我获取数据的时候发现,GuoDianHeaderStru中的子结构体成员unionLen1的uFrameLenDomain是从内存的2开始的,始终无法将它移动到从1开始的位置,请问哪位朋友能帮我吗?急切等待
------解决方案--------------------
在工程设置中,将字节对齐设为 1 Byte
------解决方案--------------------
vc6
project---setting----c/c++
category 选择 code generation---struct member alignment
是为了缓存优化而进行的处理。
我有如下结构体,
typedef struct tagGuoDianHeaderStru
{
unsigned char cStartChar1;
GuoDianLenUnion unionLen1;
}GuoDianHeaderStru;
typedef union tagGuoDianLenUnion
{
unsigned short uFrameLenDomain;
struct
{
unsigned short uFrameFlag :2;
unsigned short uUserDataLen :14;
};
}GuoDianLenUnion,*LPGuoDianLenUnion;
假定cStartChar1在内存中的地址为0,我获取数据的时候发现,GuoDianHeaderStru中的子结构体成员unionLen1的uFrameLenDomain是从内存的2开始的,始终无法将它移动到从1开始的位置,请问哪位朋友能帮我吗?急切等待
------解决方案--------------------
在工程设置中,将字节对齐设为 1 Byte
------解决方案--------------------
vc6
project---setting----c/c++
category 选择 code generation---struct member alignment
是为了缓存优化而进行的处理。