------- Additional Comments From hugh at mimosa dot com 2005-07-03 05:40 ------- Simple rule about const and volatile qualifiers (not restrict): the program can manipulate pointer values with and without their qualifiers. But when the program accesses an object that is a volatile object (i.e. defined, created, or fundamentally volatile), it must be via a volatile lvalue. And when the program accesses an object that was created const (defined, created, or fundamentally const), then it must not be modifying it.
Optimizers must not presume more. Well, there is a tricky rule about aliasing in N1124 section 6.5 (see footnote 74 on page 68), based on the unqualified types. But we're only talking about qualifiers. And another about multiple modifications between sequence points -- again, not relevant here. So I think that gcc4 is wrong for this case: the access should not be optimized out. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278