读书人

条件预处理有关问题

发布时间: 2013-03-22 09:49:50 作者: rapoo

条件预处理问题
linux下写的,用GCC调试出了问题,求各位大神给个解释条件预处理有关问题


#include <stdio.h>

#define Max(x, y) (x > y ? x:y)
int main(void)
{
int c = 0;
#if c==0 //如果换成 #if c 输出结果就没有,这个不应该是判断是否定义变量c的吗??求解判断是否定义变量c的表达式
printf("%d\n ", Max(2, 4));
#endif
return 0;
}
linux c
[解决办法]

#include <stdio.h>

#define Max(x, y) (x > y ? x:y)
int main(void)
{
#ifndef DEF_C
#define DEF_C
int c = 0; //把c的定义用保护宏保护起来
#endif

#ifdef DEF_C
printf("%d\n ", Max(2, 4));
#endif
return 0;
}


读书人网 >C语言

热点推荐