Say we have the following union:
union Color{
    int rgba;//assuming 32 bit int
    struct{
        unsigned char r;
        unsigned char g;
        unsigned char b;
        unsigned char a;
    }ColorComp;
};
It is indeed undefined behaviour (only in c++, not in c) to access an inactive element of the union(setting say rgba and trying to access r). Is there any way to have this type of behaviour(NOTE: must be well-defined by standard) where types or combinations of types can read/write to the same memory locations as other different types-i.e type-punning- in c++?
 
     
    