Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor Directive: #elif not defined?

Is there a preprocessor directive that checks whether a constant is not defined. I am aware of the #ifndef directive but I am also looking for a #elif not defined directive. Does #elif not defined exist?

This is how I would 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
like image 278
sazr Avatar asked Feb 11 '13 08:02

sazr


1 Answers

How about the

#elif !defined(...)

But you've got bigger problems - the trailing \ exclude the other directives - or rather make them illegal. So, even with the valid syntax, your definitions won't do what you want.

You'll need to move the initial define 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)
    //.....
like image 108
Luchian Grigore Avatar answered Oct 07 '22 05:10

Luchian Grigore