title: C optimisation of string literals
body: <p>I've just been inspecting the following in gdb:</p>
  <pre><code>char *a[] = {&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;four&quot;};
  char *b[] = {&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;four&quot;};
  char *c[] = {&quot;two&quot;,&quot;three&quot;,&quot;four&quot;,&quot;five&quot;};
  char *d[] = {&quot;one&quot;,&quot;three&quot;,&quot;four&quot;,&quot;six&quot;};
  </code></pre>
  <p>...and I get the following:</p>
  <pre><code>(gdb) p a
  $17 = {0x80961a4 &quot;one&quot;, 0x80961a8 &quot;two&quot;, 0x80961ac &quot;three&quot;, 0x80961b2 &quot;four&quot;}
  (gdb) p b
  $18 = {0x80961a4 &quot;one&quot;, 0x80961a8 &quot;two&quot;, 0x80961ac &quot;three&quot;, 0x80961b2 &quot;four&quot;}
  (gdb) p c
  $19 = {0x80961a8 &quot;two&quot;, 0x80961ac &quot;three&quot;, 0x80961b2 &quot;four&quot;, 0x80961b7 &quot;five&quot;}
  (gdb) p d
  $20 = {0x80961a4 &quot;one&quot;, 0x80961ac &quot;three&quot;, 0x80961b2 &quot;four&quot;, 0x80961bc &quot;six&quot;}
  </code></pre>
  <p>I'm really surprised that the string pointers are the same for equivalent words. I would have thought each string would have been allocated its own memory on the stack regardless of whether it was the same as a string in another array.</p>
  <p>Is this an example of some sort of compiler optimisation or is it standard behaviour for string declaration of this kind?</p>