C和C ++中的合并目的
我以前很舒服地使用过工会。今天,当我阅读这篇文章并得知此代码时,我感到震惊 union ARGB { uint32_t colour; struct componentsTag { uint8_t b; uint8_t g; uint8_t r; uint8_t a; } components; } pixel; pixel.colour = 0xff040201; // ARGB::colour is the active member from now on // somewhere down the line, without any edit to pixel if(pixel.components.a) // accessing the non-active member ARGB::components …