禁用gcc中的特定警告

Mat*_*del 37 gcc compiler-warnings

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

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

在GCC中使用什么?

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

Mar*_*off 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.
Run Code Online (Sandbox Code Playgroud)

但是如果你问是否有源级警告禁用,我不知道gcc中是否存在该功能.


dfa*_*dfa 12

-Wno-multichar:

如果使用多字符常量('FOOF'),请勿发出警告.通常它们在用户代码中表示拼写错误,因为它们具有实现定义的值,因此不应在可移植代码中使用.

更多信息.


pPa*_*eta 8

内部源代码写:

#pragma GCC diagnostic ignored "-Wno-multichar"

// code with  warnings but wont be displayed now...
Run Code Online (Sandbox Code Playgroud)

  • 还要注意的是,可以使用#pragma GCC诊断推送和#pragma GCC诊断pop来为少量代码设置诊断。 (2认同)

归档时间:

查看次数:

35215 次

最近记录:

6 年 前