Price With GST: ₹12000/-
Subject: Embedded Systems Level: Beginner
|
The volatile keyword is a type qualifier that prevents the objects from the compiler optimization. According to C standard, an object that has volatilequalified type may be modified in ways unknown to the implementation or have other unknown side effects. You can also say that the value of the volatile-qualified object can be changed at any time without any action being taken by the code. If an object is qualified by the volatile qualifier, the compiler reloads the value from memory each time it is accessed by the program that means it prevents from to cache a variable into a register. Reading the value from the memory is the only way to check the unpredictable change of the value.
The volatile keyword is mainly used where we directly deal with GPIO, interrupt or flag Register. It is also used where a global variable or buffer is shared between the threads.