use option -std=c99 or -std=gnu99 to compile your code除了在执行代码中加上std=c99外还有什么办法
时间: 2024-03-26 10:35:31 浏览: 157
Algorithms:DS-Algo-pythonC ++(HactoberFest 2020!)
除了在执行代码时使用命令行选项“-std=c99”或“-std=gnu99”外,你还可以在源代码中使用编译指示来指定标准。在你的源代码文件的开头,可以加入以下语句之一:
```
// For C99 standard
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Wimplicit-int"
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-extra-args"
#pragma GCC diagnostic ignored "-Wformat-security"
#pragma GCC diagnostic ignored "-Wformat-signedness"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wunreachable-code"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
// For GNU C99 standard
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Wimplicit-int"
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-extra-args"
#pragma GCC diagnostic ignored "-Wformat-security"
#pragma GCC diagnostic ignored "-Wformat-signedness"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
```
这些编译指示可以告诉编译器使用C99或GNU C99标准来解释你的代码。同时,它们还可以忽略一些在旧标准下合法但在新标准下不再推荐使用的语言特性,以便让代码更加健壮和可靠。在使用这些编译指示时,你需要确保使用的编译器支持它们。
阅读全文