So I used to think using -std=c11
and -pedantic-errors
were enough to force gcc
to only compile code that would also compile on other standard-compliant compilers (possibly on other platforms, assuming no platform-specific libraries are used), such as other versions of gcc or other compilers entirely.
However apparently compiling under mingw on Windows 7 with both -pedantic-errors -std=c11
allows code to compile that contains this:
struct foo {
//(some members)
};
struct bar {
struct foo; //note the lack of a member name
//(other members)
};
Which causes the same code, also using gcc with both -pedantic-errors -std=c11
to fail under Ubuntu with error: declaration does not declare anything
If anonymous members like aren't allowed in ISO-C11, then why did gcc let that code pass in the first place? What am I missing about what -pedantic-errors -std=c11
actually does? What other parameters (if any) do I need to ensure gcc only compiles code that is standard-compliant enough to work under other versions of gcc, on other platforms, and/or other compilers given those compilers are themselves standard-compliant? I.e. make it consistent across platforms.
I am not asking what the purpose of -pedantic-errors
is, but what parameter(s) can force gcc to only compile code that will compile everywhere (i.e. no gcc-specific extensions or non-standard stuff that doesn't always work). So -pedantic-errors
but even more strict, as -pedantic-errors
still allows extensions, it only forbids ones explicity forbidden in the standard.