c语言宏开关 使用

时间:2023-03-10 03:10:46
c语言宏开关 使用

/*

* 宏的写法,宏的作用域,当前位置开始到大括号结束,如果没有大括号,到文件结尾。

*/

#include <stdio.h>

//#define HELLO

int main(int argc, const char * argv[]) {

// insert code here...

#ifdef HELLO

printf("Hello, World!\n");

#else

printf("fjdla\n");

#endif

#define HELLO

#ifdef TEST

printf("test\n");

#else

printf("else test\n");

#endif

return 0;

}

fjdla

else test

Program ended with exit code: 0

1.vs只支持#ifdef #else #endif.      xcode支持#ifdef $elif #else #endif