How to write safe and user friendly c/c++ #define macros
问题 I have been thinking about how macros can be written to be safe, readable and intuitive. Proper use of them should be understood by the looks of them and when used incorrectly the compiler should tell you, and not let you introduce an obscure bug. When writing multiple line define macros I usually find myself constructing them like this to fullfill the desired criteria: #define macro(x) do{ \ ... some code line ; \ ... some code line ; \ }while(0) This way you can both... if (a) { macro(a); }