首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

What's the use of do while(零) when we define a macro

2012-09-02 
Whats the use of do while(0) when we define a macro?Sample code:?#include stdio.h#define INIT do

What's the use of do while(0) when we define a macro?

Sample code:

?

#include <stdio.h>#define INIT do { \printf("line1\n"); \} while (0)#define INIT_ { \printf("line1\n"); \}void correct() {if (1) INIT;elseprintf("here is the else\n");}void wrong() { if (1)  INIT_; // compile error else printf("here is the else\n");}int main(int argc, const char *argv[]) {if (1) { printf("then\n"); }; // compile errorelseprintf("else\n");}

?

Refer to?http://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro

?

?

热点排行