不知能否将整个联合体union赋值?union中各变量共享一段内存,即每次只会用其中一个变量,那么要赋值时可以直接整体赋值,还是判断后给其中一个有值的变量赋值?
struct A
{
union
{
struct B
{}b;
struct C
{}c;
struct D
{}d;
}e;
struct F
{}f;
....
}a;
A b;
现需将a中联合体中的内容赋值给b, 可以用b.e = a.e; 吗?
...全文
8377打赏收藏
联合体的赋值问题
不知能否将整个联合体union赋值?union中各变量共享一段内存,即每次只会用其中一个变量,那么要赋值时可以直接整体赋值,还是判断后给其中一个有值的变量赋值? struct A { union { struct B {}b; struct C {}c; struct D {}d; }e; struct F {}f; .... }a; A b; 现需将a中联合体中的内容赋值给b, 可以用b.e = a.e; 吗?