Volatile Declarations
Optimizer avoids memory accesses when possible
- Code which reads from memory locations outside the scope of C ( such as a hardware register) may be optimized out by the compiler
- To prevent this, use the volatile keyword
Example: wait for location to have value 0xFFFF
unsigned short *ctrl; /* wait loop */
while(*ctrl != 0xFFFF); /* loop would be removed */
volatile unsigned short *ctrl; /* safe declaration */