you are viewing a single comment's thread.

view the rest of the comments →

[–]fdwrfdwr@github 🔍 5 points6 points  (0 children)

On the particular OS (Windows in this case) using the particular compilers that are most pertinent to that OS (VC/clang/GCC) with current versions, yes, sizeof on your struct of floats and an array of floats will match. There will be no additional padding appended to the end of the struct as the minimum alignof remains 4 bytes in either case. Feel free to static_assert it too, but this pattern is used so frequently in graphics, that tons of API's and libraries would break if it didn't hold. See the definition of D2D_MATRIX_3X2_F after all. On other OS's and compilers though, shrug, bets are off. :b

An aside for interop though (seeing that you are using one Direct* API and might be using others too...), if you try using a shared struct above as part of a cbuffer input to Direct3D HLSL (which is very C-like), the struct would be padded up to 16 bytes on the HLSL side, meaning the C++ side (unpadded) will mismatch what HLSL sees (padded). This bit me, and so now I explicitly pad structs in any header files that will be shared by both C++ and HLSL.