/* 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
#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.