This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: GCC warnings for unused global variables
- From: "Kean Johnston" <jkj at sco dot com>
- To: "'Gabriel Dos Reis'" <gdr at integrable-solutions dot net>,"'Fergus Henderson'" <fjh at cs dot mu dot OZ dot AU>
- Cc: "'Richard Henderson'" <rth at redhat dot com>,"'Geoff Keating'" <geoffk at geoffk dot org>, <jbuck at synopsys dot com>,<espie at quatramaran dot ens dot fr>, <gcc at gcc dot gnu dot org>
- Date: Fri, 2 May 2003 08:38:44 -0700
- Subject: RE: GCC warnings for unused global variables
- Organization: The SCO Group
> Well, if the side effect is needed then the compiler won't remove it.
But how can the compiler possibly determine that? The compiler is just
phase 1 of a multi-phase process to create a functioning executable.
I don't know if such code exists, but it wouldn't surprise me terribly
if some smart bloke somewhere has organised, through link editor
trickery
or other object-file manipulation, that code like:
static volatile int foo;
void doit (void)
{
foo = 1;
foo = 2;
}
actually orchestrates that because the symbol is marked as volatile,
whether static or not, that it is mapped to some I/O port or special
memory location or any number of possible things, and that the mere act
of assigning a value to it writes data to the port. I belive that THAT
kind of trickery was the intent behind volatile. I don't have the
standard in front of me but I do have access to one of the committee
members and he confirms that that was indeed the intent, that volatile
should indicate to the compiler an entity that has side effects beyond
the ability for *ANY* compiler to detect.
It is critical to remember when discussing these things that gcc isnt
the final arbitrator of what constitutes valid code. There are other
standards, beyond simple language semantic standards, that it has to
interact with.
Kean