摘要:
C语言中,有时处于效率方面的考虑,采用宏的方式来替代函数。C定义宏时,常采用如下方式:1 #define MACRO_FUNC(arg) do{ \2 ... \3 }while(0)为什么要加do { .. }while(0)这样一段看似毫无用处的代码呢?这是为了保证宏方法(function)和普通方法调用方式的统一。下面来看例子:1 #define FOO(x) foo(x); bar(x);1 if(condition) 2 FOO(x);3 else// syntax error here4 ...;即使加上"{}"都没有用:1 #define FOO(x){ fo 阅读全文
posted @ 2013-03-27 14:09
Apprentice_
阅读(459)
评论(0)
推荐(0)