> From: James E Wilson > Sent: Tuesday, March 08, 2005 6:59 PM [...] > > Try re-reading the docs. -fkeep-static-consts is the default. The > purpose of this is that we don't perform this optimization at -O0 > normally, but if you use -fno-keep-static-consts, then we do. So this > option can let you remove static consts in extra cases, but will never > prevent the compiler from removing them.
Jim, Thanks for the follow-up. I filed a bug report, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20319 and note #2 summarizes some relevant, conflicting facts: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20319#c2 The gist is the documentation describes the current behavior. However, I don't think the current behavior is useful, and it does not agree with comments in the source code, nor the help line. However, as you noted __attribute__ ((used)) works well as a workaround, although it would be helpful if `used' was added to the documentation as a supported attribute that can be applied to variables. I think that the switch name -fkeep-static-consts might be more consistenly named if it was given the opposite sense and named something like -fdelete-unused-static-consts. The idea here is that by asserting the switch a particular optimization is _enabled_. Thus the optimizations performed at each level can be consistently enumerated by asserting a particular set of switches which enable specific optimizations. This would change the present user interface, however, I doubt that anyone is making extensive use of the current interface because at present only -fno-keep-static-consts, asserted at -O0 (no optimization), actually changes the default behavior of the compiler.