A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread. Volatile, can appear only once in a declaration with any type specifier; however, they cannot appear after the first comma in a multiple item declaration.
Keyword volatile can be placed before or after the data type in the variable definition. For example following declaration are identical:
Volatile T a =3;
T volatile a=3;
The declaration declares and initializes an objet with type volatile T whose value will be always read from memory
Use of volatile
- An object that is a memory-mapped I/O port
- An object variable that is shared between multiple concurrent processes
- An object that is modified by an interrupt service routine
-
Enjoy this Diwali with Y! India
Click here