Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable specific warnings in GCC [duplicate]

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.

like image 922
Matthias Wandel Avatar asked Jul 03 '09 16:07

Matthias Wandel


People also ask

How do I supress a warning in GCC?

To suppress this warning use the unused attribute (see Variable Attributes). This warning is also enabled by -Wunused , which is enabled by -Wall . Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall .

Which option of GCC inhibit all warning messages?

If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option. Inhibit all warning messages. Make all warnings into errors. Make the specified warning into an error.

How do I ignore a warning in Makefile?

Maybe you can look for CFLAGS options in Makefile and remove the -Werror flag. The Werror flag will make all warnings into errors. Show activity on this post.


1 Answers

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.

like image 81
Mark Rushakoff Avatar answered Sep 29 '22 13:09

Mark Rushakoff