I read this question and got extremely confused on what I have to do with my code. If my reading is correct, my code below is undefined according to the current standard. Below is everything I need, and I really cannot find a better way to do this. Using left shift with OR is definitely not what I want. Is it just fine to leave it this way?
EDIT: And yes I am reading n
after setting the values of rbg
and not n.
union Pixel {
unsigned char rgb[4];
uint32_t n;
Pixel():
n(0) {}
};
This is one of the parts of C++ where it is easier to check what your compiler is doing than following the standard. As far as I know most compilers still do what you expect (MSVC, GCC, CLANG). Are you thinking something esoteric?
In the following link the Sun C++ compiler is mentioned as not working:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.