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
?
?