11
#pragma GCC diagnostic push

it pop: warning: expected [error|warning|ignored] after â#pragma GCC diagnosticâ

Why? I use GCC in Linux.

I have one question, if I can't use pop/push, if the ignore only influence the compiled cpp, not influence other cpp? if some other include the cap, if influence it?

jiafu
  • 6,338
  • 12
  • 49
  • 73

1 Answers1

20

#pragma GCC diagnostic push and #pragma GCC diagnostic pop were added in gcc 4.6. You're using an older version.

These pragmas are typically used in conjunction with other #pragma GCC diagnostic directives to suppress, turn on, or turn into an error specific warnings for a small section of your code only. If they're ignored, the changes to warning levels will apply to the rest of the source file rather than just until the next #pragma GCC diagnostic pop. This may not be a problem, or it may be the end of the world; you'll need to understand your code to know for sure.

Either way, you should probably update your compiler. You wouldn't compile C99 with a C89 compiler; don't compile code containing pragmas for gcc 4.6 with gcc 4.4.

Cairnarvon
  • 25,981
  • 9
  • 51
  • 65
  • I have one question, if I can't use pop/push, if the ignore only influence the compiled cpp, not influence other cpp? if some other include my cap, if influence it? – jiafu May 15 '13 at 02:33
  • If another source file includes your file directly, the changes in diagnostics in your file will also affect that source file. – Cairnarvon May 15 '13 at 02:38
  • 9
    I think you should be able to use `_Pragma()` and conditional controls based on GCC version (for example, `#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)` as a test). – Jonathan Leffler May 15 '13 at 02:53