Thursday, January 19, 2006

Volatile

Needed For:
  • Prevent optimization when reading from a memory mapped device registers
  • Delay Loops

Usage :
volatile int xyz;
or
int volatile xyz;

Note :
volatile may cause inefficient code. e.g the following code

hwReg &= ~FUNCTION_MASK;
hwReg |= FUNCTION_BIT;

instead use the following code

hwReg = (hwReg & ~FUNCTION_MASK) | FUNCTION_BIT;

No comments: