Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable all warnings in g++ on a few lines of code

How to disable all warnings on a few lines of code. Specific warnings can be disabled using GCC diagnostic feature, but is there a flag for all warnings. I tried this way but it doesn't work

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-wall"
// some code
#pragma GCC diagnostic pop
like image 309
MKo Avatar asked Jun 20 '11 05:06

MKo


2 Answers

From here: http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html

For version 4.6 or later, you can save the state of the user's diagnostic flags. You can insert this around the line that causes the spurious warning:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    // Code that causes warning goes here
#pragma GCC diagnostic pop

In order to achieve the desired behavior, you should use "-Wall" instead of "-Wdeprecated-declarations" (and not "-wall" -- note the upcase "W").

like image 76
user1284631 Avatar answered Nov 10 '22 08:11

user1284631


I think gcc -w filename.c does so
-w flag is to ignore warnings

like image 22
peeyush Avatar answered Nov 10 '22 07:11

peeyush