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


Joe Buck <jbuck@synopsys.com> writes:

| > I'm trying to say that "volatile" is not a *reliable* feature to use
| > to write robust code with reproducible behaviour.
| > 
| > | static volatile int foo;
| > | 
| > | void test (void)
| > | {
| > | 	foo = 1;
| > | 	foo = 1;
| > | }
| > | 
| > | Does your statement mean that you believe the compiler is allowed to
| > | optimize this into:
| > | void test (void)
| > | {
| > | 	foo = 1;
| > | }
| > | ?
|  
| On Fri, May 02, 2003 at 05:18:02PM +0200, Gabriel Dos Reis wrote:
| > If it can determine that does nto change the behaviour of whole
| > program, yes, it is permitted to do so.
| 
| Gaby, surely you know that the reason that volatile is in the language

I certainly know what kinds of problems it was supposed to solve.  My
claim is what get specified in the standard does address those sorts of
problems in any reliable way. No just because some semantics was
specified for "volatile" means that it effectively addresses the
original problems.  And I think that opinion is also held by
people with respected experience on drivers and OSes area.  

I already quoted Linus on volatile, here is something from someone who
has designed and implemented languages, operating systems and
simulators:

  [...] However, I never had strong feeelings about volatile and see
  no reason to improve on the ANSI C committee's decisions in this area.
     
         B. Stroustrup, in D&E
 

| is to allow C to be used to write code that interacts with hardware,
| or with other invisible software that the compiler can't see.  If you
| can find language in the standard that suggests that one of the writes
| to foo can be legally eliminated, it's defect report time.

This is not the first discussion about the semantics of volatile --
and this certainly won't be the last one.  I do not believe, volatile
could be repaired in any way satisfactory for people.  

-- Gaby


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