If a union in C is used to for example pack a variable into a byte array as in the type described below:
typedef union
{
uint16_t integer;
byte binary[4];
} binaryInteger;
When is the actual union performed? Is it when the variables are assigned to any of the parts of the union. Or is it when that part is accessed?
Is the current or previous assignments (Depending on when it is performed) accessible in any way without causing the union to execute?
In C and C++ unions are passive, so technically they are never "performed". They tell the compiler how you want to do the memory layout for the type controlled by the union.
The compiler computes, at compile time, the size of the union
(which is at least the size of its largest member and is more if padding is needed for alignment). Then the placement of data in memory happens as you do the assignments to members of your union
.