# The VOLATILE keyword.

I have had several sugestions on how to describe volatile, If you have any input please mail me.

- The volatile keyword acts as a data type qualifier. The qualifier alters the default why in which the compiler handles the variable and does not attempt to optimize the storage referenced by it. Martin Leslie

- volatile means the storage is likely to change at anytime and be changed but something outside the control of the user program. This means that if you reference the variable, the program should always check the physical address (ie a mapped input fifo), and not use it in a cashed way.Stephen Hunt

- Here is an example for the usage of the volatile keyword:

      	/* Base address of the data input latch */

      	volatile unsigned char *baseAddr;

      	/* read parts of output latch */

      	lsb    = *handle->baseAddr;
      	middle = *handle->baseAddr;
      	msb    = *handle->baseAddr;

  Between reads the bytes are changed in the latch.

  Without the volatile, the compiler optimises this to a single assignment:

      	lsb = middle = msb = *handle->baseAddr;

  Tim Potter

- A volatile variable is for dynamic use. E.G. for data that is to be passed to an I/O port Here is an example.

      	#define TTYPORT 0x17755U

      	volatile char *port17 = (char)*TTYPORT;
      	*port17 = 'o';
      	*port17 = 'N';

  Without the volatile modifier, the compiler would think that the statement `*port17 = 'o';` is redundant and would remove it from the object code. The volatile statement prevents the compiler optimisation.Alex Arzon.

## Examples:

No example:-(

## See also:

- const qualifier

Top | Master Index | Keywords | Functions