With gcc 4.0.1, the following code on i386 (using -O3 -fomit-frame-pointer): int x; void foo (void) { ++x; } compiles to: foo: incl x ret However, when x is changed to a volatile this instead compiles to: foo: movl x, %eax incl %eax movl %eax, x ret Similar degredations in the quality of generated code exists for statements like --x, x += 2, etc when x is marked volatile. (Somewhat also related, "(void)x;" still accesses memory when x is volatile -- I suppose this might be desirable, however.)
There is another bug about this around somewhere.
This is invalid, read the comments in PR 3506 which this is a dup of. *** This bug has been marked as a duplicate of 3506 ***
>omewhat also related, "(void)x;" still accesses memory when x is volatile -- > I suppose this might be desirable, however. It is because you say to load from x.