- Used for variables
- To avoid compiler optimization
- Used for memory mapped IO
Compiler Optimization (Example)
static int val;
void func1() {
val = 0;
while (val != 0xff) // optimize as while(1)
;
}
void func2() {
val = 0;
while (*(volatile int *) &val != 0xff) // no optimization applied
;
}
No comments:
Post a Comment