------- Additional Comments From gcc2eran at tromer dot org 2005-07-02 23:30 ------- (In reply to comment #17) > Furthermore, the fundamental issue is whether this > > *(volatile int*) (int*) (&foo); > > (or equivalent) where foo has been defined volatile int should be > treated differently from > > *(volatile int*) (&foo); > > or > > foo;
How about this? int foo; *(volatile int*) (&foo); In other words, why should the compiler bother at all with the qualifiers of what the pointer "really" points to? It seems simplest and most natural to decree that any dereference of a pointer-to-volatile (regardless of its origin) is to be treated as volatile and thus never optimized away. In other words, "volatile" should treated as a property of the type of the pointer being dereferenced, not of the actual object being pointed to. By analogy, if I write long bar = 42; x = *(char*)bar; then the compiler won't optimize this (into a SEGV?) just because it can easily tell that bar didn't "really" originate from a char*. Rather, it will take my word that (char*)bar should be treated just like any char*. Sure, it might optimize this subject to the usual semantics of char* -- but in case of volatiles, these semantics (should) forbid certain optimizations. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278