| United States-English |
|
|
|
![]() |
HP Fortran 90 Programmer's Reference: HP Fortran 90 Programmer's Reference > Chapter 10 HP Fortran 90 statementsCOMMON |
|
Specifies common blocks. Syntax
DescriptionThe COMMON statement defines one or more storage areas to be shared by different program units. It also identifies the objects—that is, variables, arrays, records, and derived-type objects—to be stored in those areas. Objects in common that are shared by different program units are made accessible by storage association. Each object following a common-block name is declared to be in that common block. If /common-block-name/ is omitted, all objects in the corresponding object-list are specified to be in blank common. It is also possible to declare variables in blank common by specifying two slashes without common-block-name. Consider the following examples:
Any common block name or blank common specification can appear more than once in one or more COMMON statements within the same program unit. The variable list following each successive appearance of the same common block name is treated as a continuation of the list for that common block name. For example, the following COMMON statements:
are equivalent to:
Unlike named common blocks, blank common can differ in size in different scoping units. However, blank common cannot be initialized. As an extension, HP Fortran 90 saves all common blocks in static memory. The following restrictions apply to the use of common blocks:
Initializing common blocks As an extension to the Standard, HP Fortran 90 allows common blocks to be initialized outside of a block data program unit; for example, in a subroutine. However, note that all data initialization for a given common block must occur in the same compilation unit. HP Fortran 90 also allows blank—or unnamed—common to be initialized. Common block size The size of a common block is determined by the number and type of the variables it contains. In the following example, the common block my_block takes 20 bytes of storage: b uses 8 (2 bytes per element) and arr uses 12 (4 bytes per element):
Data space within the common area for arrays b and arr shown in this example is allocated as follows:
Allocation common block storage Common block storage is allocated at link time. It is not local to any one program unit. Each program unit that uses the common block must include a COMMON statement that contains the block name, if a name was specified. Variables assigned to the common block by the program unit need not correspond by name, type, or number of elements with those of any other program unit. The only consideration is the size of the common blocks referenced by the different program units. Correspondence between objects in different instances of the same common block is established by storage association. Note the following HP Fortran 90: when types with different alignment restrictions are mixed in a common block, the compiler may insert padding bytes as necessary. ExamplesThe following example illustrates how the same common block can be declared in different program units with different variables but the same size:
The variables i, j, and k in program unit 1 share the same storage with the array n in program unit 2: i in program unit 1 matches up with n(1) in program unit 2, j with n(2), and k with n(3). Related statementsEQUIVALENCE Related conceptsFor information about data alignment, see Table 3-1 “Intrinsic data types” and “Alignment of derived-type objects”. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||