This is some code I’m compiling on Linux:
#include <net/if.h>
int main() {
struct ifreq ifr;
}
gcc test.c is fine.
gcc -std=gnu99 test.c is fine.
gcc -std=c99 test.c fails with the following error:
test.c: In function ‘main’:
test.c:4:16: error: storage size of ‘ifr’ isn’t known
What’s different about C99 that it doesn’t like the definition of struct ifreq in Linux?
It’s a chain of consequences of preprocessing and GNU C vs C99.
First up,
net/if.h:net/if.hincludesfeatures.hstruct ifreqinside a#ifdef __USE_MISCblock.So:
__USE_MISC? — it is stuff common to BSD and System Vfeatures.hSo now,
features.h:--std=c99GCC by default defines__STRICT_ANSI__(since thats what C99 is)features.h, when__STRICT_ANSI__is on, the BSD and System V features don’t kick in. i.e.__USE_MISCis left undefined.Back up to
net/if.h:struct ifreqdoes not even exist after preprocessing! Therefore, the complaint about storage size.You can catch the whole story by doing:
or diff’ing them in any other way (like
diff --side-by-side) instead ofvimdiff.If you want this to cleanly compile with
-std=c99, you must consider the inclusion of the_DEFAULT_SOURCEfeature test macro (for glibc versions >= 2.19; for older glibc versions, use either_BSD_SOURCEor_SVID_SOURCE) so that the required functionality is enabled on top of what is offered by C99.