Forcing compiler to C99 standard

江枫思渺然 提交于 2019-12-05 02:57:12

-std=c99 won't disable language extensions (GNU C has anon structs in C99).

The -pedantic (or -pedantic-errors) flags make the compiler warn on language extensions.

Shafik Yaghmour

Both gcc and clang allow a large number of extension and here for clang. clang in general attempts to support most of the extensions that gcc does. Both will even allow you to use features that are C only in C++ for example VLAs which are a C99 feature.

In this case both are allowing you to use Unnamed struct/union fields within structs/unions in C99 mode even though it is a C11 feature.

The Language Standards Supported by GCC documents well what flags are required to turn these into warnings and errors and as far as I know clang follows the same conventions:

[...]to obtain all the diagnostics required by the standard, you should also specify -pedantic (or -pedantic-errors if you want them to be errors rather than warnings). [...]

So -pedantic will warn you if you are using an extension and -pedantic-errors will turn these warnings into an error. With -pedantic flag you should see a warning like this in gcc:

warning: ISO C99 doesn't support unnamed structs/unions [-Wpedantic]

and this in clang (see it live):

warning: anonymous structs are a C11 extension [-Wc11-extensions]

and it turn into an error with -pedantic-errors.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!