Вопрос

I have a bunch of preprocessor config options defined in config.h. I use them like so:

#if CONFIG_OPTION1
    /* do some stuff */
#endif

config.h contains their defines:

#define CONFIG_OPTION1 _DEBUG
#define CONFIG_OPTION2 _DEBUG || (NDEBUG && _WIN64)
...

The above doesn't work. I want to turn on and off these config options based on configuration (debug, release, etc) and/or other defines. It also doesn't work if I do:

#define CONFIG_OPTION1 defined(_DEBUG) || defined(NDEBUG)

I never get inside the #if CONFIG_OPTION1 even when the condition looks like it should be met. When I write #if defined(_DEBUG) that works fine, but #if with a macro as the condition fails. How can I fix this?

Это было полезно?

Решение

Well, as you've already noticed, you can't do it like that. Do something like this instead:

#if _DEBUG || (NDEBUG && _WIN64)
#   define CONFIG_OPTION2 1
#endif
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top