39

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 it’s unimaginable that it wouldn't have this feature yet, but older information 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. It’s very handy for switching on four character strings in a case statement.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matthias Wandel
  • 6,383
  • 10
  • 33
  • 31
  • 4
    Duplicates: http://stackoverflow.com/questions/487108/how-to-supress-specific-warnings-in-g http://stackoverflow.com/questions/925179/selectively-removing-warning http://stackoverflow.com/questions/965093/selectively-disable-gcc-warnings-for-only-part-of-a-translation-unit – Laurynas Biveinis Jul 04 '09 at 07:59

3 Answers3

25

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mark Rushakoff
  • 249,864
  • 45
  • 407
  • 398
13

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

dfa
  • 114,442
  • 31
  • 189
  • 228
13

Inside the source code, write:

#pragma GCC diagnostic ignored "-Wno-multichar"

// Code with warnings, but they won’t be displayed now...
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pPanda_beta
  • 618
  • 7
  • 10
  • 6
    Also nice to note that diagnostics can be set for small bits of code using `#pragma GCC diagnostic push` and `#pragma GCC diagnostic pop`. – Hector Nov 30 '17 at 03:27
  • Only a casual Stack Overflow user provided an example... – jww Jul 03 '19 at 05:58
  • 1
    The syntax that worked for me is #pragma GCC diagnostic ignored "-Wmultichar" – Clarus Apr 21 '20 at 22:21