do{} while(0)好处

替代{},实现局部作用域.

#define fun() 
    do { fun1(); fun2(); } while(0)
if (condition) fun(); else { ... }; // ok 

// compared with

#define fun() {fun1(); fun2(); }
if (condition) fun(); else { ... }; // compile error; 

避免使用goto,用break做跳出.

do {
    fun1();
    ...
    fun2();
    if (condition) {
        break;
    }
    fun3();
    fun4();
} while(0);

本文固定链接: http://www.js-code.com/c/c_61794.html