gcc开关-Wc ++ 0x-compat用于C代码

时间:2014-01-09 15:56:57

标签: c gcc gcc-warning

我正在尝试使用尽可能多的gcc警告开关来确定它们是否有助于使我的代码更清洁甚至发现问题。

我正在为C:

使用这些警告开关
warnings_common = ['-Werror', '-Wfatal-errors', '-Wpedantic', '-pedantic', '-pedantic-errors', '-Wall', '-Wextra', '-Wchar-subscripts', '-Wcomment', '-Wno-coverage-mismatch', '-Wno-cpp', '-Wdouble-promotion', '-Wformat', '-Wnonnull', '-Winit-self', '-Wimplicit-int', '-Wimplicit-function-declaration', '-Wimplicit', '-Wignored-qualifiers', '-Wmain', '-Wmissing-braces', '-Wmissing-include-dirs', '-Wparentheses', '-Wsequence-point', '-Wno-return-local-addr', '-Wreturn-type', '-Wswitch', '-Wswitch-default', '-Wswitch-enum', '-Wsync-nand', '-Wtrigraphs', '-Wunused-but-set-parameter', '-Wunused-but-set-variable', '-Wunused-function', '-Wunused-label', '-Wunused-local-typedefs', '-Wunused-parameter', '-Wno-unused-result', '-Wunused-variable', '-Wunused-value', '-Wunused', '-Wuninitialized', '-Wmaybe-uninitialized', '-Wunknown-pragmas', '-Wno-pragmas', '-Wstrict-aliasing', '-Wstrict-overflow', '-Warray-bounds', '-Wno-div-by-zero', '-Wsystem-headers', '-Wtrampolines', '-Wfloat-equal', '-Wtraditional', '-Wtraditional-conversion', '-Wdeclaration-after-statement', '-Wundef', '-Wno-endif-labels', '-Wshadow', '-Wno-free-nonheap-object', '-Wunsafe-loop-optimizations', '-Wno-pedantic-ms-format', '-Wpointer-arith', '-Wtype-limits', '-Wbad-function-cast', '-Wc++-compat', '-Wc++11-compat', '-Wcast-qual', '-Wcast-align', '-Wwrite-strings', '-Wclobbered', '-Wconversion', '-Wempty-body', '-Wenum-compare', '-Wjump-misses-init', '-Wsign-compare', '-Wsign-conversion', '-Wsizeof-pointer-memaccess', '-Waddress', '-Wlogical-op', '-Waggregate-return', '-Wno-aggressive-loop-optimizations', '-Wno-attributes', '-Wno-builtin-macro-redefined', '-Wstrict-prototypes', '-Wold-style-declaration', '-Wold-style-definition', '-Wmissing-parameter-type', '-Wmissing-prototypes', '-Wmissing-declarations', '-Wmissing-field-initializers', '-Wno-multichar', '-Wno-deprecated', '-Wno-deprecated-declarations', '-Wno-overflow', '-Woverride-init', '-Wpacked', '-Wpacked-bitfield-compat', '-Wpadded', '-Wredundant-decls', '-Wnested-externs', '-Winline', '-Wno-int-to-pointer-cast', '-Wno-pointer-to-int-cast', '-Winvalid-pch', '-Wlong-long', '-Wvariadic-macros', '-Wvarargs', '-Wvector-operation-performance', '-Wvla', '-Wvolatile-register-var', '-Wdisabled-optimization', '-Wpointer-sign', '-Wstack-protector', '-Woverlength-strings', '-Wunsuffixed-float-constants']

但是我收到了这个错误:

cc1: error: command line option '-Wc++0x-compat' is valid for C++/ObjC++ but not for C [-Werror]

因为我正在编译C文件,这似乎很奇怪:

int main(void);

int main(void) {
  return 0;
}

上面哪个开关调用'-Wc ++ 0x-compat'以及为什么?

1 个答案:

答案 0 :(得分:0)

使用gcc(和其他编译器),某些标志只是一个占位符,用于更大的标记集,如-Wall,您可以阅读gcc documentation中的标记。 / p>

如果您要禁用特定标记,请使用-Wno前缀,例如-Wno-c++0x-compat,如果您只想禁用此标记。