Won’t the union in this question cause UB when used as this:
union Data
{
unsigned int intValue;
unsigned char argbBytes[4];
};
Data data;
data.intValue = 1235347;
unsigned char alpha = data.argbBytes[0]; //UB?
I’m thinking about 9.5/1 in the standard:
In a union, at most one of the data
members can be active at any time,
that is, the value of at most one of
the data members can be stored in a
union at any time.
in general you are right, writing a value of one type to a union then reading it out as a different type is undefined behaviour. on the other hand iirc the standard explicitly allows anything to castable as a char array. it’s never been 100% clear to me which takes precedence, but all implementations I have ever used allow union casting to do what you want anyway.