2

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.

Wingblade
  • 9,585
  • 10
  • 35
  • 48
  • 2
    It is good idea to also enable `-Wall` and `-Wextra` and possibly `-Werror`. – Antti Haapala -- Слава Україні Oct 16 '17 at 18:14
  • @AnttiHaapala Will look into those, thanks! – Wingblade Oct 16 '17 at 18:15
  • [`-pedantic` explained](https://stackoverflow.com/a/46233765/918959); [GCC defaults to *GNU11* now instead of strict C11](https://stackoverflow.com/questions/14737104/what-is-the-default-c-mode-for-the-current-gcc-especially-on-ubuntu); Some things that are not standards-compliant visible in [GNU11 but not C11 mode](https://stackoverflow.com/questions/29264462/m-pi-not-available-with-gcc-std-c11-but-with-std-gnu11) etc... – Antti Haapala -- Слава Україні Oct 16 '17 at 18:17
  • 1
    Found a line in GCC's docs [here](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options) that answers my question: "A feature to report any failure to conform to ISO C might be useful in some instances, but would require considerable additional work and would be quite different from -Wpedantic. We don’t have plans to support such a feature in the near future." Looks like there is no 100% ISO C option in gcc. Using `-Wall -Wextra -Werror` alongside the pedantic option might be the next best. – Wingblade Oct 16 '17 at 18:36

0 Answers0