title: Local and static variables in C
body: <p>When compiling this:</p>
  
  <pre><code>// external definitions
  int value1 = 0;
  static int value2 = 0;
  </code></pre>
  
  <p>the gcc compiler generates the following assembly:</p>
  
  <pre><code>.globl value1
          .bss
          .align 4
          .type   value1, @object
          .size   value1, 4
  value1:
          .zero   4
          .local  value2
          .comm   value2,4,4
  </code></pre>
  
  <p>However, when i initialize the variables to a value other than zero such as:</p>
  
  <pre><code>// external definitions
  int value1 = 1;
  static int value2 = 1;
  </code></pre>
  
  <p>the gcc compiler generated the following:</p>
  
  <pre><code>.globl value1
          .data
          .align 4
          .type   value1, @object
          .size   value1, 4
  value1:
          .long   1
          .align 4
          .type   value2, @object
          .size   value2, 4
  value2:
          .long   1
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Why in the first case the values are allocated in the bss segment while in the second case in the data segment.</li>
  <li>Why value2 variable is defined as .local and .comm in the first case, while not in the second.</li>
  </ol>