#define wait_event(wq, condition)
do {
if (condition)
break;
__wait_event(wq, condition);
} while (0)
do {
if (condition)
break;
__wait_event(wq, condition);
} while (0);
#include <stdio.h>
int condition = 0;
#define wait_condition \
do { \
if (condition == 10) \
break; \
condition++; \
sleep(1); \
} while (0); \
int main()
{
int k = 1;
if (k == 1)
wait_condition; /*添加了分号编译会报错*/
else
printf ("hello world\n");
printf ("%d\n", condition);
return (0);
}
[beyes@localhost programming]$ gcc -g temp.c -o temp.exe
temp.c: 在函数‘main’中:
temp.c:19: 错误:‘else’没有对应的‘if’
{wait_condition; }
如果没有 do ... while(0)
的话, macro 除了第一个语句之外的 其它语句都会被执行到。
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |