title: C: do {...} while(0)?
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/154136/why-are-there-sometimes-meaningless-do-while-and-if-else-statements-in-c-c-macr">Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? </a><br>
    <a href="https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for">do { &hellip; } while (0)  what is it good for?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm working on some C code filled with macros like this:</p>
  
  <pre><code>#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  </code></pre>
  
  <p>Can anyone explain what this macro does, and why <code>do {} while(0)</code> is needed? Wouldn't that just execute the code once?</p>