I was thinking about how macros can be written to be safe, readable, and intuitive. The correct use of them should be understood by their appearance, and if used improperly, the compiler should tell you, and not allow you to introduce an incomprehensible error.
When writing macro definitions for multiple lines, I usually create them in such a way as to fill in the required criteria:
#define macro(x) do{ \
... some code line ; \
... some code line ; \
}while(0)
So you can ...
if (a)
{
macro(a);
}
and...
if (a)
macro(a);
else
{
...
}
A good feature of this is that if you use them incorrectly, you will get a compiler error. This will not compile, for example:
if (a)
macro(a)
else
b();
, , SW . , , - , , ?
- do {} while (0)? , , , , .
, , {} while (0) , , - ( ) .
Edit:
(!), . , :
#define MYMACRO(a,b) \
if (xyzzy) asdf(); \
else (void)0
?