常见的条件编译有两种方法
一、根据宏定义,语法如下:
#ifdef <macro>
......
#else
......
#endif
实例:
#include <stdio.h>
#define DEBUG
int main()
{
#ifdef DEBUG
printf("hello");
#else
printf("welcome");
#endif
return 0;
}
二、根据宏定义的值,语法如下:
#if <macro>
......
#else
......
#endif
实例:
#include <stdio.h>
#define DEBUG 1
int main()
{
#if DEBUG
printf("hello");
#else
printf("welcome");
#endif
return 0;
}