Volatile Variables

(ISO C, §6.7.3) When you declare a volatile variable, the Carbide C compiler takes the following precautions to respect the value of the variable:

Listing 1 shows an example of volatile variables.

Listing 1. Volatile Variables

void main(void)
{
int i[100];
volatile int a, b; /* a and b are not cached in registers. */

a = 5;
b = 20;

i[a + b] = 15; /* compiler calculates a + b */
i[a + b] = 30; /* compiler recalculates a + b */
}

The compiler does not place the value of a, b, or a+b in registers. But it does recalculate a+b in both assignment statements.