title: C++ Replacing Functions with Macros
body: <p>We have an existing function implementation in our C++ code:</p>
  
  <pre><code>void Function(int param)
  {
      printf("In Function\n");
  }
  
  int main()
  {
      Function(10);
      return 0;
  }
  </code></pre>
  
  <p>I wish to change it to call another function (by help of a macro declaration) which would accept additional params like  <strong>FILE</strong> and <strong>LINE</strong> (for debugging purpose) and then call the actual function:</p>
  
  <pre><code>#define Function(param) Function_debug(param, __FILE__,  __FUNCTION__,  __LINE__) \
  {\
      printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); \
      Function(param);\
  }
  </code></pre>
  
  <p>But the below code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define Function(param) Function_debug(param, __FILE__,  __FUNCTION__,  __LINE__) \
  {\
      printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); \
      Function(param);\
  }
  
  void Function(int param)
  {
      printf("In Function\n");
  }
  
  int main()
  {
      Function(10);
      return 0;
  }
  </code></pre>
  
  <p>Translates TO:</p>
  
  <pre><code>void Function_debug(int param, "temp.cpp", __FUNCTION__, 9) { printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); Function(int param);}
  {
      printf("In Function\n");
  }
  
  int main()
  {
      Function_debug(10, "temp.cpp", __FUNCTION__, 16) { printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); Function(10);};
      return 0;
  }
  </code></pre>
  
  <p>which gives compilation errors.</p>
  
  <p>Please direct me how to achieve the objective?</p>