如何将联合体成员定位!
如何将联合体成员定位!struct mis_t{ unsigned char a; unsigned int b; unsigned long c;}; union{ struct mis_t misu;! unsigned int e;}misu;
如上:如何将联合体 “misu” 的成员“unsigned int e” 定位到结构体的 “struct mis_t misu” 的 “unsigned int b” 成员。不要用摆放位置的方法定位可以吗? 没跟上这个场景, 既然这样,那何不直接操作结构体内的unsigned int b呢, 联合都不需要了, 标记下结构体类型即可。 struct mis_t
{
unsigned int b;
unsigned char a;
unsigned long c;
};
union
{
struct mis_t misu;
unsigned int e;
}misu;
试试吧 Negative.
The members of a union is actually the same person. They're all pointing to a same address. The only difference is they have different types. lixuyongzd 发表于 2014-6-10 10:06
struct mis_t
{
unsigned int b;
不是说了吗,不要用位置的方法啊,因为我存储的是EEProm,这样的话要改很多地址的 不要用摆放位置的方法定位可以吗?
That happens to be the simplest and best approach.
Otherwise,
1) use another struct;
2) padding.
页:
[1]