title: Global variables modified by main() and accessed by ISR()
body: <p>Here is my c code  </p>
  
  <pre><code>char global_variable = 0;
  ISR(){
      PORTA = global_variable;
      toggle_led;//to make sure that the interrupt is triggered
  }
  int main(){
      while(1){
          _delay_ms(500);
          gobal_variable++;
          PORTB = global_variable;
      }
      return 0;
  }
  </code></pre>
  
  <p>The bottom line is that I have a global variable modified by the main function and read by both the main and ISR -<strong>interrupt handler</strong>.<br>
  When the global variable is read by main I get the expected values, but in ISR I get the value that was first assigned to the global variable.<br>
  I know this is an optimization issue but I don't understand what makes the compiler see the right value in the main and the initial value in the ISR  </p>
  
  <p><strong>Note:</strong> when I modified the variable in the ISR, I read it right in the ISR but in the main I got the initial value.</p>