It seems that there are no technical reasons why floats in the structure should be aligned differently than in the array. But still there is no standardization of C ++ at the binary level.
If you want to be safe, you can add static_assert :
static_assert(offsetof(Vector, y) - offsetof(Vector, x) == sizeof(float)); static_assert(offsetof(Vector, z) - offsetof(Vector, y) == sizeof(float));
In addition, you can also disable padding using a non-cross-platform method. For Visual Studio you need #pragma pack and for gcc, you need to use the packed attribute.
source share