This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC warnings for unused global variables


Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> prj@po.cwru.edu (Paul Jarc) writes:
>| Because, since the object is volatile, it may affect the program in
>| ways unknown to the compiler.

To expand: volatile is a way for the programmer to express "I am
intentionally doing something with this variable that you cannot
detect".  E.g., the linker may be told to do something special with
it.  I may not be able to set up that external interaction portably,
but I can use volatile to portably express that the interaction is
going to be set up.

> This is my favorite peeve against the definition of "volatile".
> Does an alpha ray fired from Centauri count as a "way unknown to the
> compiler"?  From the C definition, there is nothing that preclude that.
> Then, the compiler can pretend that ways unknown to it affected the
> behaviour which is why you're seeing what you're seeing.

I'm not sure what you mean.

>| If volatile is used, then the compiler cannot know whether accesses
>| and side effects are needed.  (This is exactly what is expressed by
>| volatile.)  Do you agree or disagree?
>
> Change "cannot" to "may not" and I agree.

In what sort of case would the compiler be able to know?  A concrete
example would be helpful.

Ignoring the standard's precise wording for the moment, it seems clear
that your opinion conflicts with the standard's intent.  Do you agree
or disagree?

Back to the pragmatic argument: volatile would be a clean way to
silence this warning and preserve the id variable, assuming gcc
behaves that way.  So there is a concrete motivation for that
behavior, even though it may not be useful to everyone.  (E.g., some
of us don't use id variables.)  What motivation is there for the
optimization?  Who would find it useful?


paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]