If activation for preprocessor directive

Hello,

I want to activate an preprocessor directive with an "if" command,
something like:

if (condition){
#define SOMETHING
}

Is there a possibility to do something like this?
Currently the define is activated unregarded of the if command.

Thanks for help
Preprocessor directives are handled before the code is actually compiled so you can't use C++ language constructs to influence the preprocessing process. You could use an #if directive but then you can only check simple things, like comparing values of macros, in the condition.

1
2
3
#if condition
#define SOMETHING
#endif 

http://en.cppreference.com/w/cpp/preprocessor/conditional
Last edited on
you can compare other macros or possibly static_assert s
Topic archived. No new replies allowed.