title: Where does const string store? in stack or .data?
body: <p>I have written a simple <code>c</code> code which shows below. In this code snippet I want to verify where the const string <code>abcd</code> stores. I first guess that it should be stored in <code>.data</code> section for read-only. After a test in Debian, however, things is different from what I initial guessed. By  checking the assembly code which generated by gcc, I find it is placed in the stack frame of function <code>p</code>. But when I try it later in OSX, the string is stored in <code>.data</code> section again. Now I am confused by this. Is there any standard for the storing of const string?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  char *p()
  {
      char p[] = "abcd";
      return p;
  }
  
  int main()
  {
      char *pp = p();
      printf("%s\n",pp);
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>UPDATE: rici's answer awaken me. In OSX, the initial literal is stored in <code>.data</code> and then moved into function's stack frame later. Thus, it becomes a local variable for this function. However, gcc in Debian handle this situation is different from OSX. In Debian, gcc directly stored literal in stack instead of moving it from <code>.data</code>. I'm sorry for my carelessness.</p>