-1

I have many header files and source codes for my project in C++. I wanted to suppress warnings, therefore, came to know about #pragma warning preprocessor. I am able to suppress one kind of warning, namely 4251, by putting #pragma warning(push) #pragma warning(disable:4251) ...some declarations/prototypes #pragma warning(pop)

in the header file (utils.h) of the corresponding source file(utils.cpp), where this warning have been shown.

Now, there is another kind of warning (4146), which is occurring in my source file, clah.cpp. I am putting the same code, as mentioned, to the header file of this file (clahe.h). However, the compiler is not able to suppress this warning ? Can you please tell me if I am doing somewhere a mistake ? or, I am putting the pragma statements wrongly ? Thanks.

P.S., I am a beginner in C++.

Sanchit
  • 3,180
  • 8
  • 37
  • 53

1 Answers1

0

If you have a header that has a

#pragma warning(push) 

on top and a

#pragma warning(pop) 

at the bottom, then after the header is parsed, the warning settings are reset. You'll need to put a pragma in your cpp file as well.

#include "someheader.h"

//this is the implementation file
//some code

translates, basically, to:

//contents of the header file
#pragma warning(push) 
#pragma warning(disable:4251)

//warning is disabled here

#pragma warning(pop)

//popped - initial state (warning enabled) back

//this is the implementation file
//some code
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • Thanks @Luchian Grigore. Its working now, by putting #pragma blah blah code directly into the source file. But, I still have a doubt why for the first warning (4251), when I put #pragma blah in the header file, is working ? why not for the second case (4146), which is now working by putting #pragma blah directly in the source code. Thanks again. – Sanchit May 13 '13 at 07:55
  • @Sanchit maybe it's disabled somewhere in the project properties. Go to the properties and look for the disabled warnings section (sorry, don't know the full path off the top of my head). It could also be that 4251 is a lower level warning and you have those supressed. – Luchian Grigore May 13 '13 at 08:01