Consider this code:
// T is *any* type struct str_T{ T a, b; };
I know that there (almost always) indents between objects with different alignments, because both elements are of type T. But this time there are no different alignments. Can this statement always pass?
T
static_assert(sizeof(str_T) == 2 * sizeof(T)); // i.e. padding-free
No, this is not guaranteed. The compiler can always decide whether to use or not add extra bits between members of the structure. (If not overridden)
Quote from Project C11 , 6.7.2.1. Structure and Association Qualifiers
, , . , , ( -, , ) . ,
, , .
C11 6.7.2.1 (p6):
, ,
.