Why use do {} while(0) in macro?
May 29, 2006
Morgan wrote a good article which discussed how debugger works. You can check
this entry here(This article is in Chinese
).
I noticed one code in Morgan’s comments:
- #ifdef _DEBUG
- #define LOG_INFO(format, str) do { printf(format, str); } while (0)
- #else
- #define LOG_INFO(format, str)
- #endif
So, do you know why he use “do {} while (0)” instead of “{}” ?
Here’s the explanation:
do..while(0) in macro of LINUX kernel
More entries about : Code
