title: Is main() really start of a C++ program?
body: <p>The section $3.6.1/1 from the C++ Standard reads,</p>
  <blockquote>
  <p>A program shall contain a global
  function called <strong>main</strong>, which is the
  designated <strong>start</strong> of the program.</p>
  </blockquote>
  <p>Now consider this code,</p>
  <pre><code>int square(int i) { return i*i; }
  int user_main()
  { 
      for ( int i = 0 ; i &lt; 10 ; ++i )
             std::cout &lt;&lt; square(i) &lt;&lt; endl;
      return 0;
  }
  int main_ret= user_main();
  int main() 
  {
          return main_ret;
  }
  </code></pre>
  <p>This sample code does what I intend it to do, i.e printing the square of integers from 0 to 9, <strong>before</strong> entering into the <code>main()</code> function which is supposed to be the &quot;start&quot; of the program.</p>
  <p>I also compiled it with <code>-pedantic</code> option, GCC 4.5.0. It gives no error, not even warning!</p>
  <p>So my question is,</p>
  <p><strong>Is this code really Standard conformant?</strong></p>
  <p>If it's standard conformant, then does it not invalidate what the Standard says? <code>main()</code> is not start of this program! <code>user_main()</code> executed before the <code>main()</code>.</p>
  <p>I understand that to initialize the global variable <code>main_ret</code>, the <code>use_main()</code> executes first but that is a different thing altogether; the point is that, it <strong>does</strong> invalidate the quoted statement $3.6.1/1 from the Standard, as <code>main()</code> is NOT the <em>start</em> of the program; it is in fact the <strong>end</strong> of <em>this</em> program!</p>
  <hr />
  <p>EDIT:</p>
  <h2>How do you define the  word 'start'?</h2>
  <p>It boils down to the definition of the phrase <em>&quot;start of the program&quot;</em>. So how exactly do you define it?</p>