0

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) {}
};
Community
  • 1
  • 1

1 Answers1

1

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:

http://blog.regehr.org/archives/959

Christopher Oezbek
  • 23,994
  • 6
  • 61
  • 85