title: Is 'volatile' sufficient to prevent C++ compilers from optimizing out a silent write?
body: <p>I would like to write a function that triggers copy-on-write of a page, without having to modify any values in that page. A simple implementation:</p>
  
  <pre><code>void trigger_cow(char* addr){
      *addr = *addr;
  }
  </code></pre>
  
  <p>doesn't work because GCC will optimize out the line. If I use volatile,</p>
  
  <pre><code>void trigger_cow(char* addr){
      volatile char* vaddr = (volatile char*) addr;
      *vaddr = *vaddr;
  }
  </code></pre>
  
  <p>then this works under -O3. </p>
  
  <p>Will this "hack" work under other compilers or optimization settings?</p>
  
  <p>The description of volatile in most sites I've seen doesn't seem to describe what happens when you write to a volatile pointer, only what happens when you read from one. Thanks!</p>