在使用gcc编译的文件(几个. c和. cpp文件)中,我目前有如下内容:
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic warning "-Wall"
#endif
指定内联选项而不是仅仅使用命令行的目的是控制在哪些点之后我会更严格地进行操作(例如,#include
人名单之后).
很好用.然后,我try 添加-Wextra
:
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic warning "-Wall -Wextra"
#endif
失败了.显然,你不能在一个pragma
中使用多个选项,你必须使用几行来代替:
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic warning "-Wall"
#pragma GCC diagnostic warning "-Wextra"
#endif
- Q1:是否有一种方法可以在线指定多个选项?
接下来,我try 添加-Werror
和-pedantic
,但使用diagnostic warning
和diagnostic error
都不起作用.示例:
#pragma GCC diagnostic error "-Werror"
失败:warning: ‘-Werror’ is not an option that controls warnings
.我该怎么解决这个问题?除了diagnostic [warning|error]
还有哪些 Select -pedantic
还是-pedantic-errors
呢?因为我知道迂腐主要与标准遵从性有关,而不是诊断控制,我甚至不知道我是否可以内联指定它.