title: Allocation order on the stack
body: <p>I'm running this C code</p>
  
  <pre><code>#define STACKSIZE       65536    
  
              char d[STACKSIZE];
              if (((int) &amp;d[STACKSIZE-1]) - ((int) &amp;d[0]) + 1 != STACKSIZE) {
                   Printf ("Stack space reservation failed\n");
                   Exit ();
              } 
  
              printf("Allocated from %d to %d so for %d bytes\n", &amp;d, d+sizeof(d), sizeof(d));
  
              auto int a = 3;
              printf("Now the stack pointer is on %d\n",&amp;a);
  </code></pre>
  
  <p>And i get as output
  Allocated from -4262832 to -4197296 so for 65536 bytes
  Now the stack pointer is on -4262836</p>
  
  <p>This means that the variable "a" is put on the stack AFTER the array.
  But if I use a variable length array (an array whose length is setted in run time) I get the opposite behaviour: a is put on the the stack BEFORE the array.</p>
  
  <p>This is the code (it is the same but the size of the array is setted in runtime)</p>
  
  <pre><code> #define STACKSIZE       65536    
  
              int i = 1;
              char d[i*STACKSIZE];
              if (((int) &amp;d[STACKSIZE-1]) - ((int) &amp;d[0]) + 1 != STACKSIZE) {
                   Printf ("Stack space reservation failed\n");
                   Exit ();
              } 
  
              printf("Allocated from %d to %d so for %d bytes\n", &amp;d, d+sizeof(d), sizeof(d));
  
              auto int a = 3;
              printf("Now the stack pointer is on %d\n",&amp;a);
  </code></pre>
  
  <p>This is the output</p>
  
  <p>Allocated from -4262856 to -4197320 so for 65536 bytes
  Now the stack pointer is on -4197312</p>
  
  <p>So, what is the problem? How can I solve it (using variable length array and putting variables on the stack after it).</p>
  
  <p>Thank you!</p>