Solved

const volatile variable

Posted on 1998-09-16
2
807 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
Comment Utility
maybe a read only device register!
0
 

Accepted Solution

by:
euclid091498 earned 0 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

771 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

10 Experts available now in Live!

Get 1:1 Help Now