🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #26

Re: Meaning of the specifier volatile?

#26
From: J. Kanze
Date: Wed, 03 Jan 1996 14:54
44 lines
2998 bytes
X-Original-Date: 3 Jan 1996 10:27:41 +0100

Srinivas Vobilisetti (srv@cs.wayne.edu) wrote:

|> I referred to various books on C++ including The C++ Programming Language
|> -Bjarne Stroustrup, C++ Primer -Stanley Lipmann, etc.  Nowhere i could find
|> exact meaning of the specifier volatile. Thanks in advance for your help. I
|> would appreciate the reply at my email address srv@cs.wayne.edu

According to the ARM, volatile has no portable meaning; the precise
meaning is implementation defined.  In fact, there are a few odd
guarantees in the standard: in particular, reads and writes of a
volatile are considered part of the observable behavior of a program.
There is also a statement to the effect that the value of a volatile
object may change in ways unknown to the compiler.

What this means in practice is that the compiler should turn off
optimization of volatile variables; the program should do exactly what
you wrote, no more, no less.  Note that there is no such guarantee with
regards to other variables; the only guarantee is that the observable
behavior be "as if" the program does what you wrote.

Volatile variables are normally used precisely where things are going on
"outside of the program".  The classical example is a (memory-mapped)
real time clock; if the variable were not declared volatile, a good
compiler might detect that it was never written, and save the first
value read somewhere in a register.  Declared volatile, the compiler
must read it every time you write an expression which accesses it.

What this means exactly *IS* somewhat implementation dependant.  When
using volatile objects, you should generally eschew complex expressions,
particularly those which access the object twice in the same expression,
and read the documentation for your implementation very carefully, as to
how volatile is interpreted exactly.
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
              -- A la recherche d'une activiti dans une region francophone

    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
Technical Details
Message-ID: <4ce5ao$ds3@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
References: <4c9740$27n@netlab.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: Re: Meaning of the specifier volatile?
Followup-To: comp.lang.c++.moderated,comp.lang.c++
Date: 3 Jan 1996 14:54:16 -0000
Organization: GABI Software, Sarl.
Sender: cppmods@netlab.cs.rpi.edu
Approved: Dietmar.Kuehl@uni-konstanz.de
Message-ID: <4ce5ao$ds3@netlab.cs.rpi.edu>
References: <4c9740$27n@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu