Reinterpret struct with members of the same type as an array in a standard compliant way [duplicate]
问题 This question already has an answer here: Casting double array to a struct of doubles 6 answers In various 3d math codebases I sometimes encounter something like this: struct vec { float x, y, z; float& operator[](std::size_t i) { assert(i < 3); return (&x)[i]; } }; Which, AFAIK is illegal because implementations are allowed to spuriously add padding between members, even if they are of the same type, though none will do so in practice. Can this be made legal by imposing constraints via