title: Possible to define a function-like macro with a variable body?
body: <p>I've been looking at the <a href="http://gcc.gnu.org/onlinedocs/cpp/Macros.html">GCC docs</a> for defining macros and it looks like what I want isn't possible, but I figure if it is, someone here would know.</p>
  
  <p>What I want to do is define this macro:</p>
  
  <pre><code>synchronized(x) {
    do_thing();
  }
  </code></pre>
  
  <p>Which expands to:</p>
  
  <pre><code>{
      pthread_mutex_lock(&amp;x);
      do_thing();
      pthread_mutex_unlock(&amp;x);
  }
  </code></pre>
  
  <p>In C++ I could just make a <code>SynchronizedBlock</code> object that gets the lock in its constructor and unlocks in the destructor, but I have no idea how to do it in C.</p>
  
  <p>I realize I could use a function pointer in the form <code>synchronized(x, &amp;myfunction);</code>, but my goal is to make some C code look as much like Java as possible. And yes, I know this is evil.</p>