禁用gcc中的特定警告

时间:2009-07-03 16:10:23

标签: gcc compiler-warnings

在Microsoft编译器上,可以使用#pragma禁用特定警告,而不会禁用其他警告。如果编译器警告“必须完成”的事情,这是一个非常有用的功能。

此时GCC是否有类似功能?这似乎是一个显而易见的功能,它无法想象它还没有这个功能,但网上的旧信息表明这个功能不存在。

在GCC中使用什么?

具体来说,我喜欢使用多字符常量,比如'abc'。这些有效地评估为基数256 - 这是一个非常方便的功能,但它会触发警告。它非常便于在case语句中切换四个字符串。

4 个答案:

答案 0 :(得分:33)

这可以使用gcc的diagnostic pragmas

来完成

答案 1 :(得分:24)

来自gcc手册:

   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中是否存在该功能。

答案 2 :(得分:12)

<强> -Wno-multichar

  

如果使用多字符常量('FOOF'),请勿发出警告。通常它们表示输入错误   用户的代码,因为它们具有实现定义的值,因此不应使用   便携式代码。

More information

答案 3 :(得分:7)

内部源代码写:

#pragma GCC diagnostic ignored "-Wno-multichar"

// code with  warnings but wont be displayed now...
相关问题