From: Giovanni Mascellani Subject: Re: [PATCH vkd3d 5/8] vkd3d-shader/hlsl: Support addition for all numeric types in fold_constants(). Message-Id: <147a15c7-6635-689f-5e43-c24326f61502@codeweavers.com> Date: Thu, 20 Jan 2022 09:47:54 +0100 In-Reply-To: References: <84c45e1a-9268-11e7-9503-5bff51cd32b2@codeweavers.com> <20220106173949.82958-5-fcasas@codeweavers.com> 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-undefined-behavior > 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-and-bit_002dfields-implementation.html#Structures-unions-enumerations-and-bit_002dfields-implementation Giovanni.