This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Joy with new GCC 3.3 warnings -- HTF to shut them up?
On 01-May-2003, Richard Henderson <rth@redhat.com> wrote:
> On Fri, May 02, 2003 at 12:49:27PM +1000, Fergus Henderson wrote:
> > Does the warning still occur if the variable is declared "volatile"?
> > (It shouldn't.)
>
> Why do you believe "volatile" affects anything except
> how accesses of this variable are handled?
Well, for example the C standard states "The implementation may place a
const object that is not volatile in a read-only region of storage."
which strongly implies that an implementation may *not* place a volatile
object in read-only memory, even if the program does not contain any
write accesses to that object. (This quote is from C99 footnote 112.
Note that since this is in a footnote, it is not normative, but it
nevertheless reflects the authors' intent and understanding about the
semantics of volatile.)
More generally, the C standard states "An object that has
volatile-qualified type may be modified in ways unknown
to the implementation or have other unknown side effects."
This gives the user permission to access such objects in ways
unknown to the implementation, and therefore places a corresponding
restriction on implementations not to optimize such objects away
even if they appear to be unused.
As for why "volatile" should suppress the warning... the warning
makes sense if the object is not volatile, but in the case where
the object is volatile, the warning is likely to be spurious,
since the object may be accessed in ways unknown to GCC.
In general the compiler should not issue warnings in cases where
they are likely to be spurious.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.