
January 10th, 2013, 10:24 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 17
Time spent in forums: 5 h 19 m 31 sec
Reputation Power: 0
|
|
|
How to copy the data from a struct/union variable
Code:
struct A
{
union
{
struct B
{}b;
struct C
{}c;
struct D
{}d;
}e;
struct F
{}f;
....
}a;
A b;
I want to copy the data of a to b, or just the union part of a to b. There two ways:
(1) b = a; b.e = a.e;
(2) memcpy(&b,&a, sizeof(a)); memcpy(&b.e,&a.e, sizeof(a.e));
I am confused and not sure which method is correct.
I hope someone can explain.
Thanks!
|