Here is a macro I want to use, if X_DEFINED is defined it will be evaluated to DEFAULT_X otherwise it will be evaluated to x
#define GET_X(x) (defined(X_DEFINED) ? DEFAULT_X : x)
It doesn't compile, with the error
error: 'X_DEFINED' was not declared in this scope
Any suggestions? I want to be able to select between a parameter and a global variable based on if X_DEFINED was defined or not
defined() only works in #if and similar preprocessor directives.
You want something like this:
#ifdef X_DEFINED
#define GET_X(x) DEFAULT_X
#else
#define GET_X(x) x
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With