c - 从 gcc 引出 "unrecognized command line option"

标签 c gcc

我正在使用 gcc 7.3。例如,如果我用 int main(){ } 编译 gcc main.c -Wno-foo,编译成功,没有错误输出。

将源更改为 int main(){ int a[-1];/*uncompilable*/ 在维护构建命令的同时让我:

main.c: In function ‘main’:
main.c:3:6: error: size of array ‘a’ is negative
  int a[-1];
      ^
main.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-foo’

我可以在不向源代码中引入编译错误的情况下强制显示无法识别的命令行选项“-Wno-foo”警告/错误消息吗?

-Wfoo(没有 no-)会立即给我一条警告消息,但我宁愿保留 no-那里。 (这是为了编译器功能测试,我在构建过程中进行了测试。)

最佳答案

这显然是 gcc 的一个特性,而不是一个错误。来自GCC manual :

When an unrecognized warning option is requested (e.g., '-Wunknown-warning'), GCC emits a diagnostic stating that the option is not recognized. However, if the '-Wno-' form is used, the behavior is slightly different: no diagnostic is produced for '-Wno-unknown-warning' unless other diagnostics are being produced. This allows the use of new '-Wno-' options with old compilers, but if something goes wrong, the compiler warns that an unrecognized option is present.

因此,如果您需要知道该选项是否存在,您需要在没有 no- 的情况下使用它。先做那个;如果您发现它受支持,请执行任何需要 -Wno-foo 参数的测试。

关于c - 从 gcc 引出 "unrecognized command line option",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52577170/

相关文章:

c - 如何打印C语言中单词的最后一个字母

c - 0 和 1 的数组组合

c - 将数组传递给函数会更改其值吗?

c - 在c中将 float 打包为13位 float 进行位移位?

c - libgcov fork 和 exec 钩子(Hook)

c++ - 对于相同的 c++ 源文件,其 gcc 可执行文件在 Windows 中比在 Linux 中大 655 倍。为什么差别这么大?

c - 为什么 GCC 在添加浮点值时会给出意想不到的结果?

c - 结构体中的指针放置在两个结构体成员上

C++ 库交叉依赖 - 从 llvm 移植到 gcc

c - C 中函数的默认参数 --