title: Explanation of C++ FAQ's unsafe macro?
body: <p><a href="http://www.parashift.com/c++-faq-lite/inline-vs-macros.html">According to the C++ FAQ, macros are evil</a>:</p>
  
  <blockquote>
    <p>[9.5] Why should I use inline functions instead of plain old #define
    macros?</p>
    
    <p>Because <code>#define</code> macros are evil in 4 different ways: evil#1, evil#2,
    evil#3, and evil#4. Sometimes you should use them anyway, but they're
    still evil.
         Unlike <code>#define</code> macros, inline functions avoid infamous macro errors since inline functions always evaluate every argument exactly
    once. In other words, invoking an inline function is semantically just
    like invoking a regular function, only faster:</p>
  
  <pre><code>// A macro that returns the absolute value of i
  #define unsafe(i)  \
          ( (i) &gt;= 0 ? (i) : -(i) )
  
  // An inline function that returns the absolute value of i
  inline
  int safe(int i)
  {
    return i &gt;= 0 ? i : -i;
  }
  
  int f();
  
  void userCode(int x)
  {
    int ans;
  
    ans = unsafe(x++);   // Error! x is incremented twice
    ans = unsafe(f());   // Danger! f() is called twice
  
    ans = safe(x++);     // Correct! x is incremented once
    ans = safe(f());     // Correct! f() is called once
  }
  </code></pre>
    
    <p>Also unlike macros, argument types are checked, and necessary
    conversions are performed correctly.</p>
    
    <p>Macros are bad for your health; don't use them unless you have to.</p>
  </blockquote>
  
  <p>Can someone explain why is <code>unsafe(x++)</code> increments <code>x</code> twice? I am not able to figure out.</p>