7

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
MKo
  • 4,768
  • 8
  • 32
  • 35
  • 1
    See http://stackoverflow.com/q/965093/469210 for details on the gcc diagnostic pragma which may help. – borrible Jul 01 '11 at 10:24

2 Answers2

9

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

user1284631
  • 4,446
  • 36
  • 61
  • 6
    Using -Wall instead of a more specific tag does not work at all (at least with gcc >8 so I highly doubt it has ever worked), just leaving this here... – Peter Jul 14 '19 at 16:08
1

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

peeyush
  • 2,841
  • 3
  • 24
  • 43
  • -w flag will help if I want to disable warnings on a whole file, not on some part of it. – MKo Jun 20 '11 at 06:00
  • oh now i understood the question, will see n let you know if found any. – peeyush Jun 20 '11 at 06:20
  • btw why do you need such functionality ? – peeyush Jun 20 '11 at 08:07
  • 7
    When 3rd party headers are used, which contain a lot of warnings, but you don't have permission to change or fix them, you can include headers by surrounding them with "warning disable" code. – MKo Jun 20 '11 at 09:29