disable specific warnings in gcc

2019-01-06 17:36发布

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.

4条回答
Rolldiameter
2楼-- · 2019-01-06 18:11

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.

查看更多
家丑人穷心不美
3楼-- · 2019-01-06 18:22

Inside source code write :

#pragma GCC diagnostic ignored "-Wno-multichar"

// code with  warnings but wont be displayed now...
查看更多
迷人小祖宗
4楼-- · 2019-01-06 18:27

This can be done with gcc's diagnostic pragmas.

查看更多
SAY GOODBYE
5楼-- · 2019-01-06 18:28

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

查看更多
登录 后发表回答