Is there a way in gcc or clang (or any other compiler) to spit information about whether a struct has holes (memory alignment - wise) in it ?
Thank you.
ps: If
Gimpel's FlexeLint/PClint can do this.
$ cat tst.c
int main (void)
{
struct {
char c;
double d;
short s;
} f = { 1, 2.0, 3 };
return f.c;
}
It will report
$ flexelint -w1 +e95? tst.c
FlexeLint for C/C++ (Unix) Vers. 9.00L, Copyright Gimpel Software 1985-2014
--- Module: tst.c (C)
_
double d;
tst.c 5 Note 958: Padding of 7 byte(s) is required to align member on 8 byte
boundary
_
} f = { 1, 2.0, 3 };
tst.c 7 Note 959: Nominal struct size (18 bytes) is not an even multiple of
the maximum member alignment (8 bytes)
tst.c 7 Note 958: Padding of 6 byte(s) is required to align end of struct on
8 byte boundary