问题描述:
在C中,有个宏定义:
#define test_yes(x) p("%s .....ok!",x)
#define test_no(x) p("%s .....failed!",x)
#define test_boot(c,x) if(c)test_yes(x);else test_no(x)
于是程序中出现:
..........{
if(....)
test_boot(c1,x1)
else
test_boot(c1,x1)
}
看起来没有问题,可是:
expected statement : "}"
变成这样就对了:
..........{
if(....)
{
test_boot(c1,x1)
}
else
{
test_boot(c1,x1)
}
}
为什么呢?
原来对于宏定义里边p(.....):
#ifdef open1
#define p f_p//f_p是一个有效的函数或者是宏定义
#else
#define p xxx
#endif
再深层看一下,原来,xxx被宏定义成了 /##/
也就是空的了,所以:
........{
if(true)
else
}
显然是错误的
........{
if(true)
{
}
else
{
}
}
就是正确的了。
总结:
把宏定义看清楚,分析好了。