0

I am trying to define the following macro to disable a specific warning:

#define HUGE_VAL_DISABLE_WRN #pragma warning( disable : 4005 )

HUGE_VAL_DISABLE_WRN    // <-- errors here
#include "header.h"

and I get the following errors (all on the same line):

error C2121: '#' : invalid character : possibly the result of a macro expansion
error C2146: syntax error : missing ';' before identifier 'warning'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2065: 'disable' : undeclared identifier
error C2143: syntax error : missing ')' before ':'
error C2448: 'warning' : function-style initializer appears to be a function definition
error C2059: syntax error : 'constant'
error C2059: syntax error : ')'

What I am trying to do is to define a macro containing some preprocessor directives, which can be empty in certain conditions, but I am clearly missing something.

The complete definition is:

#if (_MSC_VER < REC_VISUAL_CPP_VERS && INTEL_MKL_VERSION < REC_INTEL_MKL_VERS)
#define HUGE_VAL_DISABLE_WRN_BEGIN \
    _Pragma("warning( push )") \
    _Pragma("warning( disable : 4005 )") // macro redefinition
#define HUGE_VAL_DISABLE_WRN_END #pragma warning( pop )
#else
    #define HUGE_VAL_DISABLE_WRN_BEGIN
    #define HUGE_VAL_DISABLE_WRN_END
#endif

From this I get:

error : this declaration has no storage class or type specifier
error : a value of type "const char *" cannot be used to initialize an entity of type "int"
error : expected a ";"
warning : parsing restarts here after previous syntax error
Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 2
    You're already using `_Pragma` to generate the first two pragmas. So use it to generate the third one too. [Pragma in define macro](https://stackoverflow.com/questions/3030099/pragma-in-define-macro) – Raymond Chen Feb 19 '20 at 20:19

1 Answers1

0

I just found out that Microsoft Visual C++ (at least up to version 2019) does not provide the _Pragma keyword (part of Standard C++11).

They have their own, slightly different, __pragma keyword:

#define HUGE_VAL_DISABLE_WRN_BEGIN \
    __pragma(warning( push )) \
    __pragma(warning( disable : 4005 )) // macro redefinition
Pietro
  • 12,086
  • 26
  • 100
  • 193