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: volatile [was: GCC warnings for unused global variables]


On 04-May-2003, Michael Eager <eager@eagercon.com> wrote:
> I don't believe there is any requirement that static variables are
> first set to zero and then set their initial value.

C++98 8.5 [dcl.init] paragraph 6: "The memory occupied by any object
of static storage duration shall be zero-initialized at program startup
before any other initialization takes place.".

> They can be
> created with the initialized value, if that can be calculated at
> compile time (e.g., if there is no constructor).

That is true for non-volatile variables, but only because the compiler
can apply the as-if rule.  As discussed earlier in this thread, the
as-if rule does not apply to volatile variables -- the standard prohibits
implementations from optimizing away accesses to volatile variables.

The only wiggle room is the fact that what constitutes "access"
to a volatile variable is implementation-defined.  
 
-- 
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.


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