Solved

const volatile variable

Posted on 1998-09-16
2
813 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now