Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 837
  • Last Modified:

const volatile variable

Hi friends,
        can anyone please say me where a constant volatile variable will be used?.
Thanks.
0
66
Asked:
66
1 Solution
 
ecwCommented:
maybe a read only device register!
0
 
euclid091498Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now