In-depth understanding of php kernel reading 1
Explanation of use of do{ }while(0)
The purpose of writing do{ }while(0) is mainly for the robustness and versatility of the basic functions of the program, and for the flexible use of some codes.
The do{ }while(0) writing method will cause the internal code to execute once and then exit. If this writing method is not used, it will cause compilation errors for programmers who do not follow {} immediately after the if statement, and for those who There is no impact on programming habits using {}.
Example:
#define SAFE_DELETE(p) do{ delete p; p = NULL} while(0) //1. Use do{ }while(0) writing method
#define SAFE_DELETE(p) { delete p; p = NULL} //2. Use {} writing
#define SAFE_DELETE(p) delete p; p = NULL //3. Use nothing
if(NULL != p) SAFE_DELETE(p) //1. No problem 2. No problem 3. There is a problem, there are 2 statements before else, compilation failed
else ...do sth...
if(NULL != p) SAFE_DELETE(p); //1. No problem 2. There is a problem, followed by brackets; Compilation failed 3. There is a problem, there are 2 items before else else ...do sth.. . // Statement, compilation failed
if(NULL != p) {SAFE_DELETE(p)} //1. No problem 2. No problem 3. No problem
else ...do sth...
http://www.bkjia.com/PHPjc/1056012.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1056012.htmlTechArticleIn-depth understanding of php kernel reading 1 Explanation of the use of do{ }while(0) do{ }while(0) writing The purpose is mainly for the robustness and versatility of the basic functions of the program and the flexible use of some codes. ...