Suppose sizeof( int ) == sizeof( float ), and I have the following code snippet:
union U{
int i;
float f;
};
U u1, u2;
u1.i = 1; //i is the active member of u1
u2.f = 1.0f; //f is the active member of u2
u1 = u2;
My questions:
- Does it have a defined behaviour? If not why?
- What is the active member of
u1after the assignment and why? - Which member of
u1can be read from after the assignment without causing an UB and why?