You may sometimes want to ignore or disable a specific type of warning that is generated when compiling your C or C++ code. The diagnostic pragmas of GCC and G++ compilers can be used to achieve this.
- For example, to ignore the warning of type
-Wenum-comparefor an entire C++ source file, add this to your code at the top:
#pragma GCC diagnostic ignored "-Wenum-compare" /** * Code that generates this warning */
- If you want the warning to be ignored only for a certain section of the code, surround it with push and pop directives:
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wenum-compare" /** * Code that generates this warning */ #pragma GCC diagnostic pop
Tried with: GCC 4.8 and Ubuntu 12.04 LTS