Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

COMMON

Statement: Defines one or more contiguous areas, or blocks, of physical storage (called common blocks) that can be accessed by any of the scoping units in an executable program. COMMON statements also define the order in which variables and arrays are stored in each common block, which can prevent misaligned data items. COMMON is an obsolescent language feature in Standard Fortran.

COMMON [ /[cname]/] var-list[[,] /[cname]/ var-list]...

cname

(Optional) Is the name of the common block. The name can be omitted for blank common (//).

var-list

Is a list of variable names, separated by commas.

The variable must not be a dummy argument, allocatable array, automatic object, function, function result, a variable with the BIND attribute,or entry to a procedure. It must not have the PARAMETER attribute. If an object of derived type is specified, it must be a sequence type or a type with the BIND attribute.

Description

Common blocks can be named or unnamed (a blank common).

A common block is a global entity, and must not have the same name as any other global entity in the program, such as a subroutine or function.

Any common block name (or blank common) can appear more than once in one or more COMMON statements in a program unit. The list following each successive appearance of the same common block name is treated as a continuation of the list for the block associated with that name. Consider the following COMMON statements:

  COMMON /glenn/ lovell, armstrong, aldrin
  COMMON /     / shepard, grissom, carpenter
  COMMON /glenn/ borman, anders
  COMMON /young/ mcdivitt, white, conrad
  COMMON schirra, cooper

They are equivalent to these COMMON statements:

  COMMON /glenn/ lovell, armstrong, aldrin, borman, anders
  COMMON         shepard, grissom, carpenter, schirra, cooper
  COMMON /young/ mcdivitt, white, conrad

A variable can appear in only one common block within a scoping unit.

A common block object must not be one of the following:

  • A dummy argument

  • A result variable

  • An allocatable variable

  • A derived-type object with an ultimate component that is allocatable

  • A procedure pointer

  • An automatic object

  • A variable with the BIND attribute

  • An unlimited polymorphic pointer

  • A coarray

If an array is specified, it can be followed by an explicit-shape array specification, each bound of which must be a constant specification expression. Such an array must not have the POINTER attribute.

A pointer can only be associated with pointers of the same type and kind parameters, and rank.

An object with the TARGET attribute can only be associated with another object with the TARGET attribute and the same type and kind parameters.

A nonpointer can only be associated with another nonpointer, but association depends on their types, as follows:

Type of Variable

Type of Associated Variable

Intrinsic numeric 1or numeric sequence 2

Can be of any of these types

Default character or character sequence 2

Can be of either of these types

Any other intrinsic type

Must have the same type and kind parameters

Any other sequence type

Must have the same type

1Default integer, default real, double precision real, default complex, double complex, or default logical.

2If an object of numeric sequence or character sequence type appears in a common block, it is as if the individual components were enumerated directly in the common list.

So, variables can be associated if they are of different numeric type. For example, the following is valid:

  INTEGER A(20)
  REAL Y(20)
  COMMON /QUANTA/ A, Y

When common blocks from different program units have the same name, they share the same storage area when the units are combined into an executable program.

Entities are assigned storage in common blocks on a one-for-one basis. So, the data type of entities assigned by a COMMON statement in one program unit should agree with the data type of entities placed in a common block by another program unit. For example:

Program Unit A

Program Unit B

COMMON CENTS

INTEGER(2) MONEY

. . .

COMMON MONEY

 

. . .

When these program units are combined into an executable program, incorrect results can occur if the 2-byte integer variable MONEY is made to correspond to the lower-addressed two bytes of the real variable CENTS.

Named common blocks must be declared to have the same size in each program unit. Blank common can have different lengths in different program units.

NOTE:

If a common block is initialized by a DATA statement, the module containing the initialization must declare the common block to be its maximum defined length.

This limitation does not apply if you compile all source modules together.

Example


PROGRAM MyProg
COMMON i, j, x, k(10)
COMMON /mycom/ a(3)
...
END
SUBROUTINE MySub
COMMON pe, mn, z, idum(10)
COMMON /mycom/ a(3)
...
END

In the following example, the COMMON statement in the main program puts HEAT and X in blank common, and KILO and Q in a named common block, BLK1:

Main Program

Subprogram

COMMON HEAT,X /BLK1/KILO,Q

SUBROUTINE FIGURE

. . .

COMMON /BLK1/LIMA,R / /ALFA,BET

 

. . .

CALL FIGURE

 

. . .

RETURN

 

END

The COMMON statement in the subroutine makes ALFA and BET share the same storage location as HEAT and X in blank common. It makes LIMA and R share the same storage location as KILO and Q in BLK1.

The following example shows how a COMMON statement can be used to declare arrays:

  COMMON / MIXED / SPOTTED(100), STRIPED(50,50)

The following example shows a valid association between subroutines in different program units. The object lists agree in number, type, and kind of data objects:

  SUBROUTINE unit1
  REAL(8)      x(5)
  INTEGER      J
  CHARACTER    str*12
  TYPE(member) club(50)
  COMMON / blocka / x, j, str, club
  ...
  SUBROUTINE unit2
  REAL(8)      z(5)
  INTEGER      m
  CHARACTER    chr*12
  TYPE(member) myclub(50)
  COMMON / blocka / z, m, chr, myclub
  ...

See also the example for BLOCK DATA.