title: Why do different C++ compilers give different results for this code?
body: <p>I'm writing some C++ codes for fun and practice, to learn more about language features. I want to know more about static variables and their behaviour in recursive functions. Trying this code in g++ compiler, I'm given expected result: </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int f(const int&amp; value)
  {
     static int result = 0;
     return result += value;
  }
  
  int main()
  {
     cout &lt;&lt; f(10) &lt;&lt; ", " &lt;&lt; f(f(10)) &lt;&lt; ", " &lt;&lt; f(f(f(10)));
     return 0;
  }
  </code></pre>
  
  <p>But my friend tested same code in Microsoft Visual C++ 6. output is <code>50, 80, 90</code> I tested it with other C++ compilers (g++, Borland, Code::blocks and MingW under Linux, Win and Mac) output was <code>110, 100, 40</code>. I can't understand how output could be <code>50, 80, 90</code> ...</p>
  
  <p>Why MSVC's output is different?</p>