title: When and why use a #define macro(x) instead of function?
body: <p>Seeing <a href="https://stackoverflow.com/questions/27592546/what-is-the-significance-of-these-defines">this question</a> made me wonder why the approach (toy example):</p>
  
  <pre><code>#define foo(x) bar[x] = 0
  </code></pre>
  
  <p>would ever be preferred over the function:</p>
  
  <pre><code>void foo(unsigned x){ bar[x] = 0; }
  </code></pre>
  
  <p>Before the question linked above, I've only seen this once before, in the PolarSSL library, where I assumed it to be some sort of optimisation, and tried not to think too much about it.</p>
  
  <p>I assume that using the preprocessor macro replaces the 'call' to be the '(not-) function body' everywhere it exists; whereas the <code>void</code> function may or may not be optimised out by the compiler, and therefore may result in a lot of branching for a small and simple operation or two.</p>
  
  <p>Is there any other benefit?</p>
  
  <p>When is the macro method preferred, and when is it better to trust the compiler?</p>