title: Inline function v. Macro in C -- What's the Overhead (Memory/Speed)?
body: <p>I searched <a href="https://stackoverflow.com/">Stack Overflow</a> for the pros/cons of function-like macros v. inline functions.</p>
  
  <p>I found the following discussion:
  <a href="https://stackoverflow.com/questions/1571392/pros-and-cons-of-different-macro-function-inline-methods-in-c">Pros and Cons of Different macro function / inline methods in C</a></p>
  
  <p>...but it didn't answer my primary burning question.</p>
  
  <p>Namely, what is the overhead in c of using a macro function (with variables, possibly other function calls) v. an inline function, in terms of memory usage and execution speed?</p>
  
  <p>Are there any compiler-dependent differences in overhead?  I have both icc and gcc at my disposal.</p>
  
  <p>My code snippet I'm modularizing is:</p>
  
  <pre><code>double AttractiveTerm = pow(SigmaSquared/RadialDistanceSquared,3);
  double RepulsiveTerm = AttractiveTerm * AttractiveTerm;
  EnergyContribution += 
     4 * Epsilon * (RepulsiveTerm - AttractiveTerm);
  </code></pre>
  
  <p>My reason for turning it into an inline function/macro is so I can drop it into a c file and then conditionally compile other similar, but slightly different functions/macros.</p>
  
  <p>e.g.:</p>
  
  <pre><code>double AttractiveTerm = pow(SigmaSquared/RadialDistanceSquared,3);
  double RepulsiveTerm = pow(SigmaSquared/RadialDistanceSquared,9);
  EnergyContribution += 
     4 * Epsilon * (RepulsiveTerm - AttractiveTerm);
  </code></pre>
  
  <p>(note the difference in the second line...)</p>
  
  <p>This function is a central one to my code and gets called thousands of times per step in my program and my program performs millions of steps.  Thus I want to have the LEAST overhead possible, hence why I'm wasting time worrying about the overhead of inlining v. transforming the code into a macro.</p>
  
  <p>Based on the prior discussion I already realize other pros/cons (type independence and resulting errors from that) of macros... but what I want to know most, and don't currently know is the PERFORMANCE.</p>
  
  <p>I know some of you C veterans will have some great insight for me!!</p>