Solved

const volatile variable

Posted on 1998-09-16
2
815 Views
Last Modified: 2008-02-01
Hi friends,
        can anyone please say me where a constant volatile variable will be used?.
Thanks.
0
Comment
Question by:66
2 Comments
 
LVL 5

Expert Comment

by:ecw
ID: 1172859
maybe a read only device register!
0
 

Accepted Solution

by:
euclid091498 earned 0 total points
ID: 1172860
A variable modified with both const and volatile will be affected by both:

- Because it is const, the compiler will not allow it to be modified BY THE CODE after it is initialized.
- Because it is volatile, the compiler will not attempt agressive optimizations that might depend on the content not being modified EXTERNALLY.

There is an example given in 'The C++ Programming Language" (p 808, 3rd edition):

extern const volatile clock;

"Two successive reads of clock might give different results."
So it is declared volatile.
It is also declared const so that it will not be possible to modify it IN THE CODE.

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need some help with listview limit text 20 105
returning a dereferenced pts in C++ 10 152
Excel/Word Add-in in what language? 5 119
trigs fail! I thought I knew how to do trignometry 3 67
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question