Consider this code. Existence of padding is guaranteed.
static_assert(_Alignof(char) < _Alignof(double), "Flip!");
static_assert(sizeof(char) < sizeof(double), "Flop!");
struct S {
char c[1];
double d;
};
union U {
char c[1];
double d;
};
static_assert(sizeof(struct S) == _Alignof(double) * sizeof(double), "Fudge!");
static_assert(sizeof(union U) == sizeof(double), "Futz!");
S s; U u;
s.c[1] = 0; // What?
u.c[1] = 0; // What?
With those static_assert
s, it's sure there's padding in the middle or at the end. Is it safe to access them?