• Keine Ergebnisse gefunden

STORAGE AND ASSOCIATION

Im Dokument COMPUTER SYSTEMS (Seite 127-132)

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

4.5 STORAGE AND ASSOCIATION

This subsection discusses the storage of variables, arrays, and common blocks, and how entities become associated.

4.5.1 STORAGE UNITS AND SEQUENCES

A numeric storage unit is a Cray word of 64 bits; a character storage unit is an 8-bit byte. A storage sequence is a contiguous group of storage units with a consecutive series of addresses. Each array and each common block is stored in a storage sequence. The size of a storage sequence is the number of storage units it contains. Two numeric storage sequences are associated if they share at least one storage unit.

An integer, real, or logical value occupies one numeric storage unit.

A character value is represented as an 8-bit ASCII code, packed eight characters per word; the storage size depends on the value's length specification. A double-precision or complex value uses a storage sequence of two numeric storage units, with the first storage unit

containing the most significant bits of a double-precision value or the real part of a complex value, and the secQnd storage unit containing the least significant bits of a double-precision value or the imaginary part of a complex value.

The ANSI FORTRAN Standard does not specify the relationship between storage units and computer words, nor does it specify any relation between numeric and character storage units.

4.5.2 STATIC AND STACK STORAGE

With static storage, any local variable that is allocated memory occupies the same address throughout program execution. Code using static storage is nonreentrant and does not adapt to multitasking.

Static storage occurs unless stack mode is specified on the CFT control statement or command.

A stack is an area of memory where storage for variables is allocated when a subprogram or procedure begins execution and is released when execution completes. When stack mode is in effect for a program, stack storage is used for all local variables except those named in SAVE, DATA, or COMMON statements. The stack expands and contracts as procedures are invoked and return. The amount of memory available for the stack is determined by the STK parameter on the LDR call or the STACK directive on the call to SEGLDR. Stacks are also called pushdown storage or

last-in-first-out (LIFO).

4.5.3 DEFINITION

A defined variable or array element has a value. An undefined variable or array element does not have a predictable value. Once defined, a variable or array element keeps a value until it becomes undefined or is redefined.

All variables and array elements are initially undefined and can be defined before or during during program execution. An initially defined variable or array element is one defined before program execution. Constants are always defined and are never redefined. A function's value is defined only when it is required.

When an entity of a given type becomes defined, all totally associated entities of different types become undefined. When an entity not of character type becomes defined, all partially associated entities become undefined. This does not apply to two entities of types real and complex or to two entities of type complex.

4.5.4 ASSOCIATION OF ENTITIES

Association of entities occurs when a storage location can be identified by different symbolic names or from different program units: that is, two entities are associated if their storage sequences are associated.

Totally associated entities have the same storage sequence. Partially associated entities share part but not all of a storage sequence. All entities using a given storage unit are affected by the unit's value or undefined status; totally associated entities have the same values and definition status.

Within a program unit, an EQUIVALENCE statement associates entities.

Across program units, entities are associated through arguments and COMMON statements. Character entities must not be associated with arithmetic or logical entities.

Partial association can exist between a double-precision or complex value and a second value of type integer, real, logical, double-precision, or complex; or between two character entities. Partial association can occur only through the use of COMMON, EQUIVALENCE, or ENTRY statements.

(ENTRY statements in a function subprogram associate any variables in the subprogram that have the same names as the ENTRY statements.) Partial association must not occur through argument association.

Example:

INTEGER I REAL R(4) COMPLEX C(2)

DOUBLE PRECISION D

EQUIVALENCE (C(2), R(2), I), (R,D)

The EQUIVALENCE statement above specifies that the following storage units are the same:

• The third storage unit of C (that is, the first unit of the second element of C)

• The second storage unit of R

• The storage unit of I

• The second storage unit of D

The storage sequences can be illustrated as follows:

Complex Real Integer

Double precision

Storage unit 1 2 1 3 1 4 1 5

C(1) C(2)

IR(1)IR(2)IR(3)IR(4)1 1_1_1

D

R(2) and I are totally associated. The following are partially

associated: R(1) and C(1), R(2) and C(2), R(3) and C(2), I and C(2), R(1) and D, R(2) and D, I and D, C(l) and D, and C(2) and D. Although C(1) and C(2) are each associated with D" C(1) and C(2) are not

associated with each other.

4.5.5 EQUIVALENCE STATEMENT

An EQUIVALENCE statement specifies the sharing of one or more storage units by two or more entities in a single program unit, in order to use storage more efficiently. This causes the association of those entities.

EQUIVALENCE (nlist)[,(nlist)] •.•

nlist List of two or more variable names, array element names, character substring names, or array names, separated by commas. nlist cannot include names of subprogram dummy arguments or variable names that are also function names.

An EQUIVALENCE statement specifies that the storage sequence of each entity in a list nlist shares the same first storage unit. This associates all entities in the list and can also indirectly associate other entities. If entities are of different data types, the EQUIVALENCE statement does not cause type conversion or imply mathematical

equivalence.

Associated entities are assigned to the same kind of storage, static or stack; static storage is used unless the stack mode option is specified on the CFT control statement or command (see section 1).

The ANSI FORTRAN Standard does not specify storage allocation methods.

4.5.5.1 Array names and array element names

The use of an array name in an EQUIVALENCE statement has the same effect as using the name of the first array element. If a variable and an array are associated, the variable does not assume the properties of an array and the array does not assume the properties of a variable. If an array element name appears in an EQUIVALENCE statement, the number of subscript expressions must be less than or equal to the number of dimensions in the array declarator for the array. When the number of subscripts is less than the number of dimensions, the lower bounds are used for the

unspecified subscripts; this does not conform to the ANSI standard, and a warning is issued.

4.5.5.2 Restrictions on EQUIVALENCE statements

An EQUIVALENCE statemen~ ffly§t not associate the storage sequences of two different common blocks in the same program unit. An EQUIVALENCE

statement must not specify the same storage unit to occur more than once in a storage sequence. Example:

DIMENSION A(2)

EQUIVALENCE (A ( 1) , B) , (A ( 2 ) , B) !Illegal statement

The above sequence is prohibited because it specifies the same storage unit for A(1) and A(2).

An EQUIVALENCE statement must not specify consecutive storage units to be nonconsecutive. For example, the following is prohibited:

REAL A(2)

DOUBLE PRECISION 0(2)

EQUIVALENCE (A( 1) , D( 1) ) , (A( 2) , D( ! Illegal statement

An EQUIVALENCE statement must not associate the storage sequences of two different common blocks in the same program unit.

Example:

COMMON/A/X COMMON/B/Y

EQUIVALENCE (X,Y) !Illegal statement

EQUIVALENCE statement association must not cause extending of 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.

Example:

COMMON IX/A

REAL B(2)

EQUIVALENCE (A,B(2» !Illegal statement

The above sequence is not permitted since it would associate an array element B(l) with a storage unit preceding A in common block X.

An entity of type character can be equivalenced only with other entities of type character. Lengths are not required to be the same. Partial overlapping between character entities can occur through equivalance association.

Example:

CHARACTER A*4,B*4,C(2)*3 EQUIVALENCE (A,C(1»,(B,C(2»

The above sequence associates A with C(2) as shown in the following illustration.

Character number:

Im Dokument COMPUTER SYSTEMS (Seite 127-132)