disable specific warnings in gcc [duplicate]

被刻印的时光 ゝ 提交于 2019-11-26 09:44:03

问题


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\".

Does GCC at this point have a similar feature? It seems like an obvious enough feature that its unimaginable that it wouldn\'t have this feature yet, but older info on the web suggests this feature doesn\'t exist.

What is one to use in GCC?

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. Its very handy for switching on four character strings in a case statement.


回答1:


From the gcc manual:

   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.

But if you're asking whether there is a source-level warning disable, I'm not aware if that feature exists in gcc.




回答2:


-Wno-multichar:

Do not warn if a multicharacter constant ('FOOF') is used. Usually they indicate a typo in the user's code, as they have implementation-defined values, and should not be used in portable code.

More information.




回答3:


Inside source code write :

#pragma GCC diagnostic ignored "-Wno-multichar"

// code with  warnings but wont be displayed now...


来源:https://stackoverflow.com/questions/1079997/disable-specific-warnings-in-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!