GCC支持所有的C标准,同时包含GCC自己的扩展。选项-std可以指定支持的C标准和GCC扩展。
1 2 3 4 | -std=c89 -std=c90 --ansi -std=c99 -std=c11 -std=c17 |
C17 is A version with corrections integrated of C11。
GNU扩展:
1 2 3 | -std=gnu90 -std=gnu99 -std=gnu11 |
但是还需要配合-pedantic和-pedantic-errors 选项,使用--ansi不会禁止所有的扩展。
举例:
1 2 3 4 5 | $ cat test .c void func(int a) { int b[a]; } |
使用--ansi编译不给出警告:
1 2 3 4 5 6 | $ cc -c test .c --ansi $ cc -c test .c --ansi -Wpedantic test .c: In function ‘func’: test .c:3:2: warning: ISO C90 forbids variable length array ‘b’ [-Wvla] int b[a]; ^ |
-Wpedantic
-pedantic
Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specifed by any ‘-std’ option used.
参考:
gcc manual.
https://stackoverflow.com/questions/2855121/what-is-the-purpose-of-using-pedantic-in-gcc-g-compiler