Electro Voyager
Electro Voyager

Reputation: 117

In C macros, where does the function named defined() come from?

In the code below, I don't understand the defined() function used inside #if; where is it defined?

Can anyone point me to a good resource in C language, where I could go deeper in these kinds of kinds of stuff?

#include <stdio.h>
#define Macro 7

void initMSP(void){
    printf("OKay with MSP platform\n");
}

void initKine(void){
    printf("Done with Kine\n");
}

//#define KINETICS  
#define MSP

int main(){

    printf("Hello world program\n");
    printf("%d\n",Macro);
    #if defined(KINETICS) && !defined(MSP) 
            initKine();
    #elif defined(MSP) && !defined(KINETICS)  
        initMSP();
    #else 
        #error "Please define a Platform "
    #endif  
}

Upvotes: 0

Views: 42

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473667

defined is not a function. It is a syntactic construct of the C preprocessor, just like #define, #ifdef, and so forth. The C language proper (to the extent that you can divorce C from its preprocessor) never directly interacts with defined. It exists during preprocessing and that's that.

Upvotes: 2

Related Questions