title: Can a static variable in a static function move to a new address in memory?
body: <p>I just upgraded to a new version of a third party library (QtPropertyBrowser for Qt 5.0).  The upgrade led to a new bug in my application which I managed to track to a static function in the library.  The function contains a static variable that is initialized the first time the function is called.  I copied down the memory location of that variable after initialization and found, as expected, that on multiple subsequent calls that the variable remained in the same memory location.  Then on a subsequent function call I noticed that the memory location and data in the static variable had changed (causing the bug in my program).</p>
  
  <p>The code looks something like this:</p>
  
  <pre><code>class ClassA
  {
      //.... 
  };
  
  class ClassB
  {
  public:
      ClassA* ptrMember;
  };
  
  static ClassA *theFunction()
  {
      static ClassB statVar = {0};
      if(!statVar.ptrMember)
          statVar.ptrMember = new ClassA();
      return statVar.ptrMember;
  }
  </code></pre>
  
  <p>I found that during multiple calls to <code>theFunction()</code> the address stored in <code>&amp;statVar</code> always remained the same, but then on a subsequent call the address in <code>&amp;statVar</code> was different and <code>statVar.ptrMember</code> was empty.</p>
  
  <p>I didn't think this was possible!  Any ideas?</p>