6

I'm wondering if there's a way to disable all warnings on a specific file (for example, using a preprocessor directive).

I'm using CImg.h and I want to get rid of the warnings involving that code.

I'm compiling both with VS (the version for Windows) and gcc (the Linux one), so I would like to have a generic way...

Thanks!

Whitewall
  • 597
  • 1
  • 7
  • 18
huff
  • 1,954
  • 2
  • 28
  • 49

2 Answers2

7

You can do it using #pragma in Microsoft compiler:

http://msdn.microsoft.com/en-us/library/2c8f766e%28VS.80%29.aspx

Something like this:

#pragma warning (push, 0)

//....header file

#pragma warning (pop)

Can't help you with gcc compiler, some info here: Selectively disable GCC warnings for only part of a translation unit?

EDIT EDIT Try push, 0.

Community
  • 1
  • 1
Igor Zevaka
  • 74,528
  • 26
  • 112
  • 128
  • But #pragma warning expects the number/code of the warning you want to disable... how would you disable *all*? Thx for the reply. – huff Jan 21 '10 at 03:56
  • Almost! Warning level 1 still produces something. Fortunately, trying #pragma warning (push, 0) *does* work (though that level is not specified on the msdn page). Now for a gcc answer... (though you earned the correct answer -- you can edit it to be more correct :D) – huff Jan 21 '10 at 06:08
  • Oh, awesome, I thought of trying level 0 but haven't found a level 1 warning to test on... – Igor Zevaka Jan 21 '10 at 07:08
  • Anyway it seems to malfunction somehow: when poping the pushed state, doesn't seem to reenable the warning level established by the CL parameters -weird, but I guess that it would not fail if I set the warning level with another #pragma... well, I'll see where it goes... – huff Jan 21 '10 at 08:02
1

Look into #pragma warning.