Как я могу определить макрос, используя другие директивы препроцессора? - PullRequest
0 голосов
/ 19 февраля 2020

Я пытаюсь определить следующий макрос для отключения определенного c предупреждения:

#define HUGE_VAL_DISABLE_WRN #pragma warning( disable : 4005 )

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

, и я получаю следующие ошибки (все в одной строке):

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 : ')'

Я пытаюсь определить макрос, содержащий некоторые директивы препроцессора, которые могут быть пустыми в определенных условиях, но я явно что-то упускаю.

Полное определение:

#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

Из этого я получаю:

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

1 Ответ

0 голосов
/ 20 февраля 2020

Я только что узнал, что Microsoft Visual C ++ (по крайней мере, до версии 2019) не предоставляет ключевое слово _Pragma (часть стандарта C ++ 11).

У них есть свои, немного отличающиеся , __pragma ключевое слово:

#define HUGE_VAL_DISABLE_WRN_BEGIN \
    __pragma(warning( push )) \
    __pragma(warning( disable : 4005 )) // macro redefinition
...