[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Volatile Variables

(K&R, §A4.4) When you declare a variable to be volatile the C compiler takes the following precautions:

Listing 3.1 shows an example of volatile variables.

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;
    i[a + b] = 30;
}

The compiler does not place the value of a, b, or a+b in registers. Also, the compiler recalculates a+b in both assignment statements.


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 17, 2000