'volatile' keyword changes a variable write into a write followed by a read. This makes it quite difficult to access hardware registers, which can confuse the hardware when read. For instance, an access to a volatile address produces:
movw $100, 10000
movw 10000, %ax
This only happens when using g++. If I change the filename from vol_bug.cpp to vol_bug.c, the code does not write, then read from a volatile location.
redhat Linux 7.2
gcc3 vol_bug.cpp -Os -S
State-Changed-Why: This was fixed by http://gcc.gnu.org/ml/gcc-patches/2002-01/msg00041.html
and follow up patches in gcc 3.1.