COMMON

Purpose

The COMMON statement specifies common blocks and their contents. A common block is a storage area that two or more scoping units can share, allowing them to define and reference the same data and to share storage units.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-COMMON--+-----------------------------+--object_list--------->
           '-/--+-------------------+--/-'                
                '-common_block_name-'                     

>--+-----------------------------------------------------+-----><
   | .-------------------------------------------------. |   
   | V                                                 | |   
   '---+---+--/--+-------------------+--/--object_list-+-'   
       '-,-'     '-common_block_name-'                       

object
Read syntax diagramSkip visual syntax diagram
>>-+-variable_name--+--------------------------------+-+-------><
   |                '-(--explicit_shape_spec_list--)-' |   
   |                        (1)                        |   
   '-procedure_pointer_name----------------------------'   

Notes:
  1. Fortran 2003

Rules

object cannot refer to a dummy argument, automatic object, allocatable object , or an object of a derived type that has an allocatable ultimate component, pointee, function, function result, or entry to a procedure, or a variable with the BIND attribute. object cannot have the STATIC or AUTOMATIC attributes.

If an explicit_shape_spec_list is present, variable_name must not have the POINTER attribute. Each dimension bound must be a constant specification expression. This form specifies that variable_name has the DIMENSION attribute.

A given variable_name or procedure pointer name can only appear once in all common block object lists within a scoping unit. Their names cannot be made accessible by use association.

If object is of derived type, it must be a sequence derived type. Given a sequenced structure where all the ultimate components are nonpointers, and are all of character type or all of type default integer, default real, default complex, default logical or double precision real, the structure is treated as if its components are enumerated directly in the common block.

Data pointers that are storage associated shall have deferred the same type parameters. Furthermore, a data pointer object in a common block can only be storage associated with pointers of the same type, type parameters, and rank.

An object in a common block with TARGET attribute can be storage associated with another object. That object must have the TARGET attribute and have the same type and type parameters.

Pointers of type BYTE can be storage associated with pointers of type INTEGER(1) and LOGICAL(1). Integer and logical pointers of the same length can be storage associated if you specify the -qintlog compiler option.

A procedure pointer can be storage associated only with another procedure pointer; both interfaces must be either explicit or implicit. If both interfaces are explicit, their characteristics must be the same. If both interfaces are implicit, both must be subroutines or both must be functions with the same type and type parameters.

If you specify common_block_name, all variables specified in the object_list that follows are declared to be in that named common block. If you omit common_block_name, all variables that you specify in the object_list that follows are in the blank common block.

Within a scoping unit, a common block name can appear more than once in the same or in different COMMON statements. Each successive appearance of the same common block name continues the common block specified by that name. Common block names are global entities.

The variables in a common block can have different data types. You can mix character and noncharacter data types within the same common block. Variable names in common blocks can appear in only one COMMON statement in a scoping unit, and you cannot duplicate them within the same COMMON statement.

See Interoperability of common blocks for BIND information.

By default, common blocks are shared across threads, and so the use of the COMMON statement is thread-unsafe if any storage unit in the common block needs to be updated by more than one thread, or is updated by one thread and referenced by another. To ensure your application uses COMMON in a thread-safe manner, you must either serialize access to the data using locks, or make certain that the common blocks are local to each thread. The Pthreads library module provides mutexes to allow you to serialize access to the data using locks. The lock_name attribute on the CRITICAL directive also provides the ability to serialize access to data. See CRITICAL /END CRITICAL for more information. The THREADLOCAL and THREADPRIVATE directives ensure that common blocks are local to each thread. See THREADLOCAL and THREADPRIVATE for more information.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us