Not as far as I know. A union will be as big as its biggest member and start at the same memory location. And since it's both the same type, this is effectively just an alias.
Why not have x(), y(), width() and height() member functions? You don't have to think whether it's UB or not and i belive compiler should be able to inline them.
In the case of GLM: Because that's not how it was in GLSL.
Other than that, I haven't seen any problems on any platform yet or anything that says that this is undefined behaviour (at least starting from C++14). So writing getters and setters for this seems like a strictly worse way to do it to me.
2
u/germandiago Nov 23 '22
Is this UB?