Solved

const volatile variable

Posted on 1998-09-16
2
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

626 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