Preprocessor directive: #elif not defined?
Is there a preprocessor directive that checks if a constant is not defined. I know the directive #ifndef
, but I am also looking for the directive #elif not defined
. Does it exist #elif not defined
?
This is how I will use it:
#define REGISTER_CUSTOM_CALLBACK_FUNCTION(callbackFunctName) \
#ifndef CUSTOM_CALLBACK_1 \
#define CUSTOM_CALLBACK_1 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#elif not defined CUSTOM_CALLBACK_2 \
#define CUSTOM_CALLBACK_2 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#elif not not defined CUSTOM_CALLBACK_3 \
#define CUSTOM_CALLBACK_3 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#endif
+3
source to share
1 answer
What about
#elif !defined(...)
But you're in big trouble - the final one \
rules out other directives - or rather, makes them illegal. This way, even with valid syntax, your definitions won't do what you want.
You will need to wrap the initial definition inside the conditions.
#ifndef CUSTOM_CALLBACK_1
#define CUSTOM_CALLBACK_1
#define REGISTER_CUSTOM_CALLBACK_FUNCTION(callbackFunctName) \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName)
#elif !defined(CUSTOM_CALLBACK_2)
//.....
+12
source to share