I’m a bit new to macros so go easy, but we have an external library that generates loads of warnings when compiled under windows (its not so bad on linux). Its a header only library so I can’t just turn the warnings off for the whole library, but I can disable each section that is generating the warnings (which is a bit tedius)
So I was wondering if it is possible to create a macro, so that instead of typing the following below, i could do it in a couple of lines.
#ifdef _WIN32
#pragma warning (push)
#pragma warning(disable : 4355) // 'this' used in base member initialize list
#endif
code that generates warning
#ifdef _WIN32
#pragma warning (pop)
#endif
However, when i try and create the macro such as below
// Disable a warning on win32 platform
// You must call DISABLE_WIN32_PRAGMA_WARN_END afterwards
#define DISABLE_WIN32_PRAGMA_WARN (nnn) \
#ifdef _WIN32 \
#pragma warning (push) \
#pragma warning(disable : nnn ) \
#endif
#define DISABLE_WIN32_PRAGMA_WARN_END \
#ifdef _WIN32 \
#pragma warning (pop) \
#endif
However I get the following errors when compiling using VS2012
error C2121: '#' : invalid character : possibly the result of a macro expansion
error C2065: 'nnn' : undeclared identifier
error C2351: obsolete C++ constructor initialization syntax
error C2612: trailing 'identifier' illegal in base/member initializer list
1 Answer