[comp.lang.c] do {...} while 0 vs if

volpe@underdog.crd.ge.com (Christopher R Volpe) (09/25/90)

I noticed a lot of people using the "do {...} while(0)" method for
generating multi-statement macros that "work" like statements. 
I used to also, until I defined one similar to the following:
   #define SOME_MACRO do {.... return(val);} while (0)

with the intent to use it as in the following:
   if (some_test) SOME_MACRO; else {morestuff};

Unfortunately, the compiler gives me "statement not reached" warnings
about the test after the "while", since that test is never reached, even
though the compiler "should" optimize it out. Redefining it as
   #define SOME_MACRO if (1) {.... return(val);} else
solved the problem. 

Is there any reason while the "do" method is better than the "if"
method? 
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com