title: Difference between an inline function and static inline function when accessing a static variable
body: <p>I encountered an interesting case while reading others code.</p>
  
  <p>In the head file, defined a static variable and an inline function are simplified as following: </p>
  
  <pre><code>static int ply;
  
  inline int WTM(){return ply;}
  </code></pre>
  
  <p>and the function is called in some other <code>cpp</code> file that include this head.</p>
  
  <pre><code>cout &lt;&lt; ply &lt;&lt; " " &lt;&lt; WTM();
  </code></pre>
  
  <p>The strange thing is that at where this function is called, the variable <code>ply</code> inside that inline function has different value from the same variable just before it outside the function. </p>
  
  <p>The output is 0 1;</p>
  
  <p>I checked all the file and both <code>ply</code> and <code>WTM()</code> just have this single definition.</p>
  
  <p>After that I have changed the code to the following:</p>
  
  <pre><code>static int ply;
  
  static inline int WTM(){return ply;}
  </code></pre>
  
  <p>The two value became the same.</p>
  
  <p>My compiler is <code>g++ (GCC) 4.4.7</code> with default setting.</p>
  
  <p>I searched about this phenomenon and get to this two link:
  <a href="https://stackoverflow.com/questions/12836171/difference-between-an-inline-function-and-static-inline-function">Difference between an inline function and static inline function</a>
  and
  <a href="http://gcc.gnu.org/onlinedocs/gcc/Inline.html" rel="nofollow noreferrer">http://gcc.gnu.org/onlinedocs/gcc/Inline.html</a>
  but still don't understand why this could happen (especially for why they could have different values in the first situation). I wonder if someone can tell me how the compiler will expand those two pieces of code (I tried using <code>-E</code> but it seems not working on inline function).</p>