禁用 GCC 中的特定警告 [英] Disable specific warnings in GCC
问题描述
在 Microsoft 编译器上,可以使用 #pragma 禁用特定警告,而不会禁用其他警告.如果编译器对必须完成"的事情发出警告,这是一个非常有用的功能.
On Microsoft compilers, specific warnings can be disabled with a #pragma, without disabling other warnings. This is an extremely useful feature if the compiler warns over something that "has to be done".
此时的 GCC 是否有类似的功能?这似乎是一个足够明显的功能,令人难以想象的是它还没有此功能,但网络上的旧信息表明此功能不存在.
Does GCC at this point have a similar feature? It seems like an obvious enough feature that it’s unimaginable that it wouldn't have this feature yet, but older information on the web suggests this feature doesn't exist.
在 GCC 中使用什么?
What is one to use in GCC?
特别是,我喜欢使用多字符常量,比如abc".这些有效地评估为基数 256 数字 - 一个非常方便的功能,但它会触发警告.在case语句中切换四个字符串非常方便.
Specifically, I like to use multi-character constants, like 'abc'. These evaluate effectively as a base 256 number - a very handy feature, but it triggers a warning. It’s very handy for switching on four character strings in a case statement.
推荐答案
来自 GCC 手册:
许多选项都有以 -f 或 -W 开头的长名称---例如,-fforce-mem、-fstrength-reduce、-Wformat 等等.这些大部分都有积极和消极的形式;-ffoo 的否定形式是-fno-foo.本手册仅记录了这两种形式中的一种,以一个不是默认值.
Many options have long names starting with -f or with -W---for example, -fforce-mem, -fstrength-reduce, -Wformat and so on. Most of these have both positive and negative forms; the negative form of -ffoo would be -fno-foo. This manual documents only one of these two forms, whichever one is not the default.
但如果你问是否有源级警告禁用,我不知道 GCC 中是否存在该功能.
But if you're asking whether there is a source-level warning disable, I'm not aware if that feature exists in GCC.
这篇关于禁用 GCC 中的特定警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!