Hi,
Il 19/01/22 19:30, Francisco Casas ha scritto:
That's clever, but maybe too clever! While it should work, I am inclined to leave it as it is, for readability and for having the peace of mind that it won't surprise us in the future.
We would have to remember to keep hlsl_constant_value as a union and, for instance, I have the same concern as this person: https://stackoverflow.com/questions/11373203/accessing-inactive-union-member... and the answers don't seem conclusive.
I agree with Zebediah, in our case it's ok to do that.
More specifically, notice that that question was about C++, not about C, and often the two languages tend to differ in this kind of things. Answers are both about C and C++, but at least for C this is not undefined behavior (see for example the first part of https://stackoverflow.com/a/11996970/807307). It is still implementation-defined, but here and in many other places we assume that we use GCC (or a compatible thing), which defines it the way we like:
https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Structures-unions-enumerations-...
Giovanni.