Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
volatile tells the compiler that other processes will modify this variable, so do not optimize it.
For example, lets say the main routine continually tests a variable in a loop waiting for an interrupt routine to change it. If the variable is not labeled volatile, the compiler will optimize out the testing loop as it believes it can predict that the loop will never be true.
It is used when the variable can be changed outside of the program or function you are in, such as an I/O port or a global variable changed by an interrupt routine.
It forces the compiler to read the variable before using it to stop it optimising it away.
For example, lets say the main routine continually tests a variable in a loop waiting for an interrupt routine to change it. If the variable is not labeled volatile, the compiler will optimize out the testing loop as it believes it can predict that the loop will never be true.
Volatile mean tell the compiler not to optimized that variable.. This because when we use the variable in the fuction it is always store that variable in the register for accessing speed but when the data must change follow the input all the time. Such as the I/O Map architecture it is recommand that you declare the variable using volatile keyword.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.