Consider this code. Indentation 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;
u.c[1] = 0;
With these static_assert
s, he is sure that the overlay will be in the middle or at the end. Is access to them safe?
source
share