天天看點

C語言的新奇玩法| 函數裡套宏定義

看好多開源代碼裡都用到了宏定義的函數程式設計,這裡寫個demo體驗一下。

#ifndef __PRINT_0_
#define __PRINT_0_

#include <stdio.h>
int defineFunc(){
    int x;
#ifdef __PRINT_0_
    x = 0;
#else
    x = 1;
#endif
    return x;
}
int main(){
    int res = defineFunc();
    printf("%d\n", res);
    return 0;
}

#endif      
#include <stdio.h>
int defineFunc(){
    int x;
#ifdef __PRINT_0_
    x = 0;
#else
    x = 1;
#endif
    return x;
}
int main(){
    int res = defineFunc();
    printf("%d\n", res);
    return 0;
}      

繼續閱讀