• Keine Ergebnisse gefunden

COMMON BLOCKS

Im Dokument COMPUTER SYSTEMS (Seite 132-136)

20 FORMAT ("SAM'S NOT HERE") STOP

4.6 COMMON BLOCKS

1011021031041051061071

1----

A

----I

1----

B

----I

1--C(1)--I--C(2)--1

A common block is an area of memory that can be referenced by any

program unit in a program, and serves as a means of passing values among program units and external procedures. A common block can be referenced by any subprogram in which the common block is declared.

A named common block has a name specified in a COMMON statement, along with the names of variables or arrays stored in the block; its size is the same for use by all program units. Different subprograms can include COMMON statements specifying the same common block. A blank common

block is declared in the same way but without a name; its size need not be constant for use by different program units. Only a named common block can be initialized by a DATA statement.

Within an executable program, the common block storage sequences of all common blocks with the same name share the same first storage unit. The same is true of all blank common blocks. This associates entities among different program units.

4.6.1 COMMON STATEMENT

The COMMON statement associates entities in different program units.

This allows different program units to share storage units and to define and reference the same data.

COMMON [/[cb]/]nlist[,/[cb]/nlist] ...

cb Common block name. The blank (unnamed) common block is specified when a cb does not appear between slashes.

nlist List of variable names, array names, and array declarators separated by commas. Names of dummy arguments of a

subprogram cannot appear in the list.

The entities occurring in nlist following a block name cb are

declared to be in common block cb. If the first cb is omitted, its enclosing slashes are optional and all entities in nlist are specified to be in blank common.

Any cb (or an omitted cb for blank common) can occur more than once in one or more COMMON statements in a program unit. The nlist following each successive appearance of the same common block name continues the preceding list for that common block name.

If any entity in a common block is a character variable or character array, all entities in that common block must be of type character. If the common block is defined in any other procedure, the entities in that procedure must be character entities.

EQUIVALENCE statement association must not extend a common block storage sequence by adding storage units preceding the first storage unit of the first entity specified in a COMMON statement for the common block.

4.6.2 REFERENCING COMMON BLOCKS

Because a common block associates entities by storage sequence rather than by name, the names and types of variables and arrays can differ between different subprograms. To be referenced, a datum in a common block must be defined, and the reference must be of the type which was declared for that datum in the subprogram where the reference appears.

Qualifications:

• An integer variable that has been assigned an executable statemel~t

label must not be referenced in any program unit other than the one in which it was assigned.

• Either part of a complex datum can be referenced as a real datum.

• If any entity in a common block is of type character, all entities in the block must be of type character, and the common block

definitions in all subprograms must be of type character.

In a subprogram that has declared a named or blank common block, the entities in the block remain defined after the execution of a RETURN or END statement.

The ANSI FORTRAN Standard specifies that variables in a named common block become undefined if no executing program unit has declared the common block.

4.6.3 COMMON BLOCK NAMES

A symbolic name is the name of a common block if it appears as a block name in a COMMON statement. A common block name is global to the executable program.

A common block name in a program unit may also be the name of any local entity other than a constant, intrinsic function (unless the function is not referenced), or a local variable that is also an external function in a function subprogram. If a name is used for both a common block and a local entity, the appearance of that name in any context other than as a common block name in a COMMON or SAVE statement identifies only the local entity. A common block name can be the name of a constant, intrinsic function, or external procedure.

The ANSI FORTRAN Standard does not allow a common block name to be the name of a constant, intrinsic function, or external procedure.

4.6.4 COMMON BLOCK STORAGE SEQUENCE

For each common block, a common block storage sequence is formed as follows.

• A storage sequence is formed, consisting of the storage sequences of all entities listed in a COMMON statement. The sequence order is determined by the order of these entities.

• This storage sequence is extended to include all storage units of any storage sequence associated with it by an EQUIVALENCE

statement. The sequence can be extended only by adding storage units beyond the last storage unit. Entities associated with an entity in a common block are considered to be in that common block.

4.6.5 COMMON BLOCK SIZE

The size of a common block is the size of its common block storage sequence, including any extensions of the sequence resulting from association by an EQUIVALENCE statement.

The maximum size of common blocks within a program depends on the loader being used: LDR uses the size of the first common block as a maximum;

SEGLDR uses the maximum size specified in the whole program as a maximum. Blank common blocks within an executable program are not

required to be of the same size and can increase, decrease or remain the same as each program unit is compiled.

The ANSI FORTRAN Standard does not include variable size for named common blocks.

4.6.6 EXTENDED MEMORY COMMON BLOCKS

CFT allows common blocks to contain more than 4 million words of memory by using the extended memory addressing (EMA) feature (see the EMA CPU characteristic in subsections 1.1 and 1.2). When the EMA CPU

characteristic is specified, all variables declared in named and blank common blocks are addressed as though they are allocated beyond 4 million words of memory. The variables declared in an extended memory common block can be used like variables declared in a regular common block.

A fatal error message is issued when the NOEMA CPU characteristic is used and any common block is declared to contain more than 4 million words.

4.6.7 TASK COMMON STATEMENT

When multitasking is used, some common blocks may need to be local to a task. CFT allows common blocks to be declared local to a task by using the task common block extension. All variables declared in a task common block are considered local to a task. If multiple tasks execute code containing the same task common block, each task will have a separate copy of the block.

The keyword TASK must precede the keyword COMMON when a named common block is declared. A task common block is allocated at task invocation.

The format of a task common block is as follows.

Format:

TASK COMMON [/[cb]/]nlist[,/[cb]/nlist] ..•

cb Task common block name

nlist List of variable names, ar.ray names, and array declarators, separated by commas. Names of subprogram dummy arguments cannot appear in the list.

The variables in nlist cannot be preset with data. With this

exception, the variables can be used like the other variables declared in COMMON.

Stack allocation must be used with task common blocks (see the STACK option in the CFT control statement or command in subsections 1.1 and 1.2). If static allocation is used, all task common blocks are treated as regular cornmon blocks.

The ANSI FORTRAN Standard does not provide for task common blocks.

Im Dokument COMPUTER SYSTEMS (Seite 132-136)