Why use do { } while (0) in macro definition? [duplicate]
Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? I met code like below: #define ev_io_init(ev,cb,fd,events) \ do { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ } while (0) I want to know why the author use do { } while (0) here. Is there any difference with this? #define ev_io_init(ev,cb,fd,events) { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ } BTW: the code is from libev, ev_local.h Consider if( something ) function1(); else function2(); If function1() is actually a macro, just using { } requires you to