Example:
int foo=0;
while (foo != 10)
//do sth
if this code is optimized, the compiler will make the loop always true because it seems it would not be changed through the code (while (true)).
Cases you need to declare a variable as Volatile:
- Memory-mapped peripheral registers
- Global variables modified by an interrupt service routine
- Global variables accessed by multiple tasks within a multi-threaded application
No comments:
Post a Comment