January 10th, 2013, 11:24 PM
How to copy the data from a struct/union variable
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.
January 11th, 2013, 01:49 AM
> (1) b = a; b.e = a.e;
Since this actually works, I'd go with this approach.