title: Is the order of writes to separate members of a volatile struct guaranteed to be preserved?
body: <p>Suppose I have a struct like this:</p>
  <pre><code>volatile struct { int foo; int bar; } data;
  data.foo = 1;
  data.bar = 2;
  data.foo = 3;
  data.bar = 4;
  </code></pre>
  <p>Are the assignments all guaranteed not to be reordered?</p>
  <p>For example without volatile, the compiler would clearly be allowed to optimize it as two instructions in a different order like this:</p>
  <pre><code>data.bar = 4;
  data.foo = 3;
  </code></pre>
  <p>But with volatile, is the compiler required not to do something like this?</p>
  <pre><code>data.foo = 1;
  data.foo = 3;
  data.bar = 2;
  data.bar = 4;
  </code></pre>
  <p>(Treating the members as separate unrelated volatile entities - and doing a reordering that I can imagine it might try to improve locality of reference in case <em>foo</em> and <em>bar</em> are at a page boundary - for example.)</p>
  <p>Also, is the answer consistent for current versions of both C and C++ standards?</p>