title: Which function is responsible for class object initialization at global scope in C++?
body: <p>I'm trying to know more about global scope object initialization in c++. For a <code>class/struct</code> object at global scope, which function is responsible for it's initialization?</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct foo {
    foo() {
      std::cout &lt;&lt; "foo's constructor" &lt;&lt; std::endl;
    }
  };
  
  foo bar;
  
  int main() {
    std::cout &lt;&lt; "main" &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>I know that the output will be:</p>
  
  <pre><code>foo's constructor
  main
  </code></pre>
  
  <p>What I do not understand is why? Which function is responsible for global object initialization (like <code>int main</code> is called by <code>__libc_start_main</code>)?</p>
  
  <p>Also what kind of initialization is it (static or dynamic)? From what I think it is dynamic initialization.</p>