Why use do {} while(0) in macro?
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
Maybe you are also interested in the following entries:
How to offset Lilina's display timezone?
Get the Stack trace information in Java SE 5.0
Feeling about IAsk - user experience based search engine