I have an union with 2 pointers to different data types:
union{
UCHAR *_rawData;
RGB *_RGBData;
};
typedef struct RGB
{
UCHAR red;
UCHAR green;
UCHAR blue;
}RGB;
later in code...
_rawData = new UHCAR[126];
_RGBData = new _RGBData[42]; //3 times lower than rawData
So my question is.. Is it safe to make union like this? Theoretically both variables use 126 bytes so it should be ok but I'm not sure so I asked here
The union by itself is valid, but only one member of the union can be active at any time:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With