title: Does default parameterizing in C++ functions push the default values onto stack?
body: <p>If a function has 20 parameters (pointers)(4 used in the example) with default values for all of them pointed to NULL, does that that mean each call to this function does a PUSH to stack a NULL value during runtime?</p>
  
  <p>A sample such function might look like:</p>
  
  <pre><code>function test(val1=NULL, val2=NULL, .... val20=NULL)
  </code></pre>
  
  <p>I am asking this to maximize speed and by reducing # cycles during the function calls.</p>
  
  <h1>TEST CASE (THERE ARE SOME EXTRA THINGS IN HERE AS WELL)</h1>
  
  <pre><code>// ArgsListTest.cpp
  // @author Mathew Kurian
  
  #include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;time.h&gt;
  
  using namespace std;
  
  // Look at the difference in psuedo-assembly code
  // My knowledge in compiler is little, but I can see that
  // that there are unncessary cycles being wasted for this part.
  
  // **** With array (this example) *****
  // LOAD         Reg, memAddressOfArray
  // WRITETOMEM   Reg, ptrToVar1
  // INCREMENT    sp
  // WRITETOMEM   Reg, ptrToVar2
  // DECREMENT    sp
  // PUSH         ptrToArray
  // JUMP         test
  
  //  ***** IDEALLY SUPPOSED TO LIKE THIS *****
  // PUSH        ptrToVar2
  // PUSH        ptrToVar1
  // JUMP        test
  
  class Base
  {
  public:
      virtual int test(void* arguments[])
      {
          cout &lt;&lt; "Base function being called. VTable lookup ignored since there is no virtual." &lt;&lt; endl;
          cout &lt;&lt; *static_cast&lt;int*&gt;(arguments[0]) &lt;&lt; endl;   // Parameter 1 (Thinks there is only 1 parameter!)
  
          int x = 5;      x += 1; // Random math to prevent optimizations. (I hope)
          return x;
      }
  };
  
  class Derived : public Base
  {
  public:
      virtual int test(void* arguments[])
      {
          // cout &lt;&lt; "Derived function being called. VTable lookup during runtime. Slight overhead here!" &lt;&lt; endl;
  
          // cout &lt;&lt; *static_cast&lt;string*&gt;(arguments[0]) &lt;&lt; endl; // Parameter 1
          // cout &lt;&lt; *static_cast&lt;int*&gt;(arguments[1]) &lt;&lt; endl;   // Parameter 2
  
          int x = 5;      x += 1;
          return x;
      }
  };
  
  class Base2
  {
  public:
      virtual int test(void* arg1 = NULL, void* arg2 = NULL, void* arg3 = NULL, void* arg4 = NULL)
      {
          // cout &lt;&lt; "Base2 function being called. VTable lookup ignored since there is no virtual." &lt;&lt; endl;
  
          // cout &lt;&lt; *static_cast&lt;string*&gt;(arg1) &lt;&lt; endl; // Parameter 1
          // cout &lt;&lt; *static_cast&lt;int*&gt;(arg2) &lt;&lt; endl;   // Parameter 2
          int x = 5;      x += 1;
          return x;
      }
  
      virtual int test2()
      {
          int x = 5;      x += 1;
          return x;
      }
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      Base * base = new Derived;
      Base2 * base2 = new Base2;
  
      int r = 0;
      string * str = new string("sunny");
      int * vale = new int(20);
      int iterations = 1000000000;
  
      //================================================================================
  
      printf("Using No-Parameters [%d iterations]\n", iterations);
  
      clock_t tStart = clock();
  
      for (int x = 0; x &lt; iterations; x++)
      {
          r = base2-&gt;test2();
      }
  
      printf("Time taken: %.9fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
  
      //================================================================================
  
      printf("Using Array [%d iterations]\n", iterations);
  
      tStart = clock();
  
      for (int x = 0; x &lt; iterations; x++)
      {
          void * arguments[] = { str, vale };
          r = base-&gt;test(arguments);
      }
  
      printf("Time taken: %.9fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
  
      //================================================================================
  
      printf("Using Default-Parameters [%d iterations]\n", iterations);
  
      tStart = clock();
  
      for (int x = 0; x &lt; iterations; x++)
      {
          r = base2-&gt;test(str, vale);
      }
  
      printf("Time taken: %.9fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
  
      //================================================================================
  
      // cout &lt;&lt; "NOTE: Derived class has no extra methods although the parameter counts are different.\n      Parent class doesn't even realize parameter 1 exists!" &lt;&lt; endl;
  
      std::getchar();
  
      return 0;
  }
  </code></pre>
  
  <h1>OUTPUT (WHICH DOESNT MAKE LOGICAL SENSE)</h1>
  
  <p><img src="https://i.stack.imgur.com/lOboC.jpg" alt="enter image description here"></p>
  
  <h1>Why is the first test slower than the second? And how creating an array is actually faster than just <code>PUSH NULL</code>?</h1>