volatile

K

karthikbalaguru

what is "volatile"? what is the use of this?


"volatile" is a 'qualifier' that is used at the time of
declaration. It tells the compiler that the value of the
variable may change at any time-without being manipulated from
your code. For example , registers(Status Registers) whose
values may change asynchronously at any point of time from
external factors . Also, it is very useful in ISRs and
Multithreaded programming.

It is very common in Embedded to declare status register as
volatile. It implies that it can be changed by external
hardware at any point of time during the lifetime of the
program and the compiler must not optimise it if it is not
used in the current program.It is for optimisation .

There are lot of good articles regarding 'volatile' in
internet. Try googling. :)
 
S

santosh

lak said:
what is "volatile"? what is the use of this?

It indicates to the compiler that the object so qualified should not be
subject to optimisation, particularly that it can be modified
asynchronously from outside the program. Typically this means that
reading the object, actually accesses it, and not some compiler cached
copy, even if the compiler believes that the object has not changed. It
will also prevent the compiler from keeping the object entirely in a
register, even if the object's lifetime is small.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top