The VOLATILE attribute specifies that the value of an object is entirely unpredictable, based on information local to the current program unit. It prevents objects from being optimized during compilation.
The VOLATILE attribute can be specified in a type declaration statement or a VOLATILE statement, and takes one of the following forms:
Type Declaration Statement:
Statement:
A variable or COMMON block must be declared VOLATILE if it can be read or written in a way that is not visible to the compiler. For example:
If an array is declared VOLATILE, each element in the array becomes volatile. If a common block is declared VOLATILE, each variable in the common block becomes volatile.
If an object of derived type is declared VOLATILE, its components become volatile.
If a pointer is declared VOLATILE, the pointer itself becomes volatile.
A VOLATILE statement cannot specify the following:
Examples
The following example shows a type declaration statement specifying the VOLATILE attribute:
INTEGER, VOLATILE :: D, E
The following example shows a VOLATILE statement:
PROGRAM TEST
LOGICAL(1) IPI(4)
INTEGER(4) A, B, C, D, E, ILOOK
INTEGER(4) P1, P2, P3, P4
COMMON /BLK1/A, B, C
VOLATILE /BLK1/, D, E
EQUIVALENCE(ILOOK, IPI)
EQUIVALENCE(A, P1)
EQUIVALENCE(P1, P4)
The named common block, BLK1, and the variables D and E are volatile. Variables P1 and P4 become volatile because of the direct equivalence of P1 and the indirect equivalence of P4.
For More Information: