do...while(0)的作用
摘要:
1. 消除代码的冗余以及无需使用goto语句。int* p = new int; bool bOK(true); do{ bOK = func1(); if(!bOK) break; bOK = func2(); if(!bOK) break; //... }while(0); delete p; p = NULL;2. 宏定义中的do...while(0)避免悬空else分支导致编译失败或运行错误如:#define safe_delete(p) do{ delete p; p = NULL;}while(0)if (p != NULL) safe_delete(p);els... 阅读全文
posted @ 2013-06-30 19:44 eric.geoffrey 阅读(197) 评论(0) 推荐(0) 编辑