title: C++ initialization of automatics and scope
body: <p>Can anyone point me to a reference in the C++ standard that guarantees me that the automatic <em>char</em>* <em>q</em> in the function <em>foo1()</em> will always be initialized after <em>p = bar()</em> has been called in <em>foo1()</em>. I am so used to creating a new block like in <em>foo2()</em> and am wondering if I am being overly blockish and paranoid of the optimizing compiler. Or I am correct in being paranoid and should not assume that the compiler will not optimize the code such that <em>p = bar()</em> will always be called before <em>q(p)</em>?
  Thanks!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;strings.h&gt;
  
  
  char* bar()
  {
      char* t = (char*)malloc(15);
      strcpy(t, "Hello World!");
      return t;
  }
  
  void foo1(void)
  {
      char* p = NULL;
  
      printf("foo1: do some stuff\n");
  
      p = bar();
  
      printf("foo1: do some more stuff\n");
  
      char* q(p);
  
      printf("foo1: q says:%s\n", q);
  
      free(p);
  }
  
  void foo2(void)
  {
      char* p = NULL;
  
      printf("foo2: do some stuff\n");
  
      p = bar();
  
      printf("foo2: do some more stuff\n");
  
      // is this block necessary?
      {
          char* q(p);
  
          printf("foo2: q says:%s\n", q);
      }
  
      free(p);
  }
  
  int main(int ac, char* av[])
  {
      foo1();
      foo2();
      return 0;
  }
  </code></pre>