C multi-line macro issue: why not use if(1){...} instead of do{...}while(0) in multi-line macro definition
c, c++, gcc
Solution
if you code something like
if (somecondition)
EXIT_CIRCULATION();
else
break;
then the expansion of your macro won't behave as you intuitively expect. The `else` would apply to your `if (1)` and will never happen.
Problem
I want to invoke multi-line macro in circulation to break/continue it. If I use "do{...}while(0)" in multi-line macro definition, break/continue is only effect on "do {...}while(0)", not the circulation who invoke this macro. So I consider using "if(1){...}" in multi-macro definition. ``` #define EXIT_CIRCULATION() \ if(1){ \ break; \ } void func(){ while(1){ ... EXIT_CIRCULATION(); ... } } ``` But I doubt wheather it is a good way to use "if(1){...}" in macro definition, because I can not find any example in internet. Thanks!