VOLATILE

Purpose

The VOLATILE attribute is used to designate a data object as being mapped to memory that can be accessed by independent input/output processes and independent, asynchronously interrupting processes. Code that manipulates volatile data objects is not optimized.

Syntax

Read syntax diagramSkip visual syntax diagram
                     .-,---------------------------.   
                     V                             |   
>>-VOLATILE--+----+----+-variable_name-----------+-+-----------><
             '-::-'    +-⁄--common_block_name--⁄-+     
                       '-derived_type_name-------'     

Rules

If an array name is declared volatile, each element of the array is considered volatile. If a common block is declared volatile, each variable in the common block is considered volatile. An element of a common block can be declared volatile without affecting the status of the other elements in the common block.

If a common block is declared in multiple scopes, and if it (or one or more of its elements) is declared volatile in one of those scopes, you must specify the VOLATILE attribute in each scope where you require the common block (or one or more of its elements) to be considered volatile.

If a derived type name is declared volatile, all variables declared with that type are considered volatile. If an object of derived type is declared volatile, all of its components are considered volatile. If a component of a derived type is itself derived, the component does not inherit the volatile attribute from its type. A derived type name that is declared volatile must have had the VOLATILE attribute prior to any use of the type name in a type declaration statement.

If a pointer is declared volatile, the storage of the pointer itself is considered volatile. The VOLATILE attribute has no effect on any associated pointer targets.

If you declare an object to be volatile and then use it in an EQUIVALENCE statement, all of the objects that are associated with the volatile object through equivalence association are considered volatile.

Any data object that is shared across threads and is stored and read by multiple threads must be declared as VOLATILE. If, however, your program only uses the automatic or directive-based parallelization facilities of the compiler, variables that have the SHARED attribute need not be declared VOLATILE.

If the actual argument associated with a dummy argument is a variable that is declared volatile, you must declare the dummy argument volatile if you require the dummy argument to be considered volatile. If a dummy argument is declared volatile, and you require the associated actual argument to be considered volatile, you must declare the actual argument as volatile.

Declaring a statement function as volatile has no effect on the statement function.

Within a function subprogram, the function result variable can be declared volatile. Any entry result variables will be considered volatile. An ENTRY name must not be specified with the VOLATILE attribute.

Fortran 2008 beginsAn object can have the VOLATILE attribute inside a BLOCK construct, regardless of whether the object has the VOLATILE attribute outside the BLOCK construct. Fortran 2008 ends

Using -qxlf2003=volatile

If an actual argument is an array section or an assumed-shape array, and the corresponding dummy argument has the VOLATILE attribute, that dummy argument shall be an assumed-shape array.

If an actual argument is a pointer array, and the corresponding dummy argument has the VOLATILE attribute, that dummy argument shall be an assumed-shape array or a pointer array.

If the actual argument is an array section having a vector subscript, the dummy argument is not definable and shall not have the VOLATILE attribute.

Host associated entities are known by the same name and have the same attributes as in the host, except that an accessed entity may have the VOLATILE attribute even if the host entity does not.

In an internal or module procedure, if a variable that is accessible via host association is specified in a VOLATILE statement, that host variable is given the VOLATILE attribute in the local scope.

A use associated entity may have the VOLATILE attribute in the local scoping unit even if the associated module entity does not.

Table 1. Attributes compatible with the VOLATILE attribute
ALLOCATABLE  1  INTENT PUBLIC
ASYNCHRONOUS OPTIONAL SAVE
AUTOMATIC  3  POINTER STATIC  3 
CONTIGUOUS  2  PRIVATE TARGET
DIMENSION PROTECTED  1   
Note:
  •  1  Fortran 2003
  •  2  Fortran 2008
  •  3  IBM extension

Examples

      FUNCTION TEST ()
        REAL ONE, TWO, THREE
        COMMON /BLOCK1/A, B, C
        ...
        VOLATILE /BLOCK1/, ONE, TEST
! Common block elements A, B and C are considered volatile
! since common block BLOCK1 is declared volatile.
        ...
        EQUIVALENCE (ONE, TWO), (TWO, THREE)
! Variables TWO and THREE are volatile as they are equivalenced
! with variable ONE which is declared volatile.
      END FUNCTION

Related information