• Aucun résultat trouvé

EQUIVALENCE Considerations-COMMON Statement

Dans le document FORMAT (3(1) STOP (Page 157-162)

mM Extension

VS FORTRAN allows you to equivalence character and noncharacter data.

' -_ _ _ _ _ _ _ _ _ End of mM Extension _ _ _ _ _ _ _ _ _ ...

When you use the EQUIVALENCE statement together with the COMMON statement, there are additional complications resulting from storage allocations.

The following examples illustrate programming considerations you must take into account.

Your program contains the following items:

REAL R4A, R4B, R4M(3,5), R4N(7) DOUBLE PRECISION R8A, R8B, R8M(2)

mM Extension LOGICAL·1 L1A

1...-_ _ _ _ _ _ _ _ _ End of mM Extension _ _ _ _ _ _ _ _ _ ---' LOGICALL4A

which are defined in the common area as follows:

COMMON R4A, R8M,

~,

R8A, L4A, R4M and which results in the following inefficient displacements:

Name Displacement Boundary

R4A 0 Doubleword

R8M 4 Word (should be doubleword)

mM Extension

L1A 20 Word

'--_ _ _ _ _ _ _ _ _ End of mM Extension _ _ _ _ _ _ _ _ _ ---' R8A

L4A R4M

21 29 33

Byte (should be doubleword) Byte (should be word) Byte (should be word)

Now add an EQUIVALENCE statement to this inefficient COMMON statement:

1. First Example (valid but inefficient):

EQUIVALENCE (R4M(1,1), R4B) EQUIVALENCE (R4B, R8B)

This results in the following additional inefficiencies:

Name Displacement Boundary

R4B 33 Byte (same as R4M(1,1»

R8B 33 Byte (same as R4M(1,1) and R4B)

which means that both R4B and R8B are now also inefficiently aligned.

2. Second Example (illegal):

EQUIVALENCE (R8A, R4N(7»

Chapter 6. Subprograms and Shared Data

131

This is illegal because the seventh element of R4N has the same displacement as R8A, or 21.

This means that the first element of R4N is located 24 bytes (4*6) before this, at displacement -3. It is illegal to extend a common area to the left in this way.

3. Third Example (valid but inefficient):

EQUIVALENCE (R8A, R4N(2»

EQUIVALENCE (R4M, R4N(5»

This has the following results:

Name

33 Byte (same position as R4N(5) This is valid because the EQUIVALENCE statement places R4M at displacement 33, the same displacement as that specified in the COMMON statement. However, it is inefficient because both R4N and R4M begin at byte boundaries.

4. Fourth Example (illegal):

EQUIVALENCE (R8A, R4N(2»

EQUIVALENCE (R4M, R4N(4»

This has the following illegal results:

Name

29 Byte (same position as R4N(4) This is valid because the EQUIVALENCE statement

This is illegal, because the EQUIVALENCE statement (which places R4M at displacement 29) contradicts the COMMON statement (which places R4M at displacement 33). The COMMON statement controls the displacement of R4M, not the EQUIVALENCE statement.

~ Using Blank and Named Common (Static and Dynamic)

There are two forms of common storage you can specify: blank common and named common.

• Blank Common - An unnamed common storage area (common block) is a blank common area, when no name is specified for the storage area.

• Named Common - You can name common storage areas (or blocks of storage )-known as named common. Blocks given the same name occupy the same space.

mM Extension

• Dynamic Common - A named common with the DC compiler option

specifying the named common area to be allocated at execution time. Note that this type of common cannot be initialized at compile time.

Note: VS FORTRAN allows you to place character and noncharacter variables and/ or arrays in the same common area.

For more information, see "Using Dynamic Common above the 16-Megabyte Line" on page 314.

L...-. _ _ _ _ _ _ _ _ _ _ End of IBM Extension _ _ _ _ _ _ _ _ _ _ _ There are different FORTRAN rules for blank and named common areas, which may cause you to choose one type over the' other, depending on what you want your program to do.

The differences are:

• You can define only one blank common block in an executable program, although you can specify more than one COMMON statement defining items in blank common; you cannot assign blank common a name. You can define many named common blocks, each with its own name.

• You can define blank common as having different lengths in different program units. You must define a given named common block with the same length in every program unit that uses it.

• You can't assign initial values to variables and array elements in blank common.

• In named common, you can assign initial values to variables and array

elements, through a block data subprogram that contains DATA statements or explicit specification statements.

In a COMMON statement, you specify a common block name by enclosing it in slashes. The following example defines a named common block, PAYROL, that contains the variables FICA, MANHRS, SICKDA: .

COMMON/PAYROL/FICA,MANHRS,SICKDA

Chapter 6. Subprograms and Shared Data

133

If the common name is omitted, a blank common is assumed. Or you can define blank common and named common in ·a single COMMON statement by omitting a name, and defining the blank common area first:

COMMON A,C,G/PAYROL/FICA,MANHRS,SICKDA

and the variables A, C, and G are placed in blank common.

You can also specify blank common items after named common items, by placing two consecutive slashes before the list of blank common variables:

For example, in the following statement:

COMMON A, C, G IPAYROL/FICA,MANHRS,SICKDAII JJ, VMN, LP7 you've defined the variables A, C, G, JJ, VMN, and LP7 in blank common, and in that order. You've defined PAYROL as named common, containing FICA, MANHRS, and SICKDA, in that order.

If you specify more than one COMMON statement in a program, the definitions are cumulative through the program. For example, if you specify the following two COMMON statements:

COMMON A, B, C

IRI

D, E

lSI

F

COMMON G, H

lSI

I, J

IR/P II

W

they have the same effect as if you specified the single statement:

COMMON A,B,C,G,H,W

IRI

D, E, P

lSI

F, I, J

The name of a named common cannot be used in PROGRAM, SUBROUTINE, FUNCTION, ENTRY, or BLOCK DATA statements. It cannot be an intrinsic function name that is referenced in the same program unit. In particular, you cannot use a name that is an entry name in an intrinsic function library module that is referenced. For example, if you use the ICHAR intrinsic function, you cannot use 'CHAR' or 'LEN' as the name of your common block because botp of these names are entry point names in the same library routine which also has ICHAR as an entry point. (For details, see "Module Names" in VS FORTRAN Language and Library Reference.)

You can, however, use the generic name of a function as the name of a common block if the intrinsic function use will reference a specific name different from the generic name. For example, you can call the name of your comIilon block SIN, and use SIN as a non-REAL*4 intrinsic function.

A named common can be specified as a dynamic common by use of the dynamic common (DC) option, described under "Using the Compiler Options" on

page 157. A dynamic common is allocated just before the program containing it is executed.

Dynamic common is useful in the MVS/XA environment for utilizing the expanded address capability. Also, the size of a load module is reduced when dynamic common is used, since no space is allocated for the dynamic common in the object modules that make up the load module.

If a named common is declared as dynamic common, all program units sharing that common must declare it as dynamic in order for correct program references to the common to be established when the program is executed.

Dans le document FORMAT (3(1) STOP (Page 157-162)