title: Is volatile required here?
body: <p>EDITED and refined my question after Johannes's valuable answer    </p>
  
  <pre><code>bool b = true;
  volatile bool vb = true;    
  void f1() { }
  void f2() { b = false; }
  
  void(* volatile pf)() = &amp;f1; //a volatile pointer to function
  
  int main()
  {
     //different threads start here, some of which may change pf 
     while(b &amp;&amp; vb)
     {
        pf();
     }
  }
  </code></pre>
  
  <p>So, let's forget  synchronization for a while. The question is whether b has to be declared volatile. I have read the standard and sort-of know the formal definition of volatile semantics (I even almost understand them, the word almost being the key). But let's be a bit informal here. If the compiler sees that in the loop there is no way for b to change then unless b is volatile, it can optimize it away and assume it is equivalent to <code>while(vb)</code>. The question is, in this case pf is itself volatile, so is the compiler allowed to assume that b won't change in the loop even if b is not volatile?</p>
  
  <p>Please refrain from comments and answers which address the style of this piece of code, this is not a real-world example, this is an experimental theoretical question.
  Comments and answers which, apart from answering my question, also address the semantics of volatile in greater detail which you think I have misunderstood are very much welcome.</p>
  
  <p>I hope my question is clear. TIA</p>
  
  <p><em><strong>Editing once more:</em></strong><br>
  what about this?  </p>
  
  <pre><code>bool b = true;
  volatile bool vb = true;
  void f1() {}
  void f2() {b = false;}
  void (*pf) () = &amp;f1;
  
  #include &lt;iosrteam&gt;
  int main()
  {
     //threads here
  
     while(b &amp;&amp; vb)
     {
        int x;
        std::cin &gt;&gt; x;
        if(x == 0)
           pf = &amp;f1;
        else
           pf = &amp;f2;    
        pf();
     } 
  }
  </code></pre>
  
  <p>Is there a principal difference between the two programs. If yes, what is the difference?</p>