title: Return value of static volatile variable in C Function
body: <p>Two scenarios: </p>
  
  <ol>
  <li><p>a function that returns the value of a static volatile variable</p></li>
  <li><p>direct access to a volatile variable</p></li>
  </ol>
  
  <p><strong>Q1:</strong> Will an assignment from a function call behave differently than assignment directly from a volatile variable? </p>
  
  <p><strong>Q2:</strong> If so, is there a standard way to access a volatile through a function return?</p>
  
  <pre><code>/*timer.h*/
  extern volatile uint8_t directFlag;
  uint8_t getReturnFlag(void);
  
  
  
  /*timer.c*/
  volatile uint8_t directFlag = 0;   
  static volatile uint8_t returnFlag = 0;
  
  uint8_t getReturnFlag(void)
  {
      return returnFlag;
  }
  
  void timerISR(void)
  {
      directFlag++;
      returnFlag++;
  }
  
  
  
  /*main.c*/
  #include "timer.h"
  
  void main()
  {
      uint8_t a = 0;
      uint8_t b = 0;
  
      while(1)
      {
          a = directFlag;
          b = getReturnFlag(); /* Can this be optimized out? */
  
      }
  }
  </code></pre>