• Aucun résultat trouvé

ASSOCIATION OF ARGUMENTS

Dans le document CRAY® COMPUTER SYSTEMS (Page 92-95)

LANGUAGE ELEMENTS AND STRUCTURE

PRINT *, VARIABLE END

13 RETURN END

2.6.1 ASSOCIATION OF ARGUMENTS

A procedure call associates actual arguments with dummy arguments: the first actual argument with the first dummy argument, and so on. The association is valid only if the arguments are of the same type. A dummy argument is undefined if it is not associated with an actual argument.

Association of actual and dummy arguments ends when the procedure

finishes executing; association is not continued to the next execution of the procedure.

The following requirements apply to the use of arguments:

• Dummy procedures and nesting: When a procedure name is used as an argument, its corresponding dummy argument must be a dummy

procedure name (see 2.6.4). Association of arguments can be carried through more than one level of procedure reference; any invalid association makes further associations also invalid.

• Alternate return specifiers must be associated with asterisk dummy arguments (see 2.5.3.2).

• Variables and constants: If the actual argument is a variable name, array element name, or substring name, the associated dummy argument can be defined or redefined within the subprogram. A dummy argument must not be redefined within the subprogram if the associated actual argument is a constant, the name of a constant, a function reference, or an expression involving operators or enclosed in parentheses.

• Associating two dummy arguments: If a subprogram reference causes two dummy arguments in the referenced subprogram to become

associated with each other, neither dummy argument can become defined in the subprogram. For example, if two dummy arguments are associated with the same actual argument, they become

associated with each other and cannot legally become defined.

Common block entities: If a subprogram call associates a dummy argument with an entity in a common block, and the common block is declared or referenced in the subprogram, neither the common block entity nor the argument can become defined within the subprogram.

Example:

In calling program unit: In called subprogram:

COMMON ICB/B CALL XYZ (B)

SUBROUTINE XYZ (A) COMMON ICB/C

The above subroutine call associates A with B; Band C are associated in common block CB. Neither A nor C can become defined during the execution of subroutine XYZ or by any procedures i t references.

2.6.2 ACTUAL ARGUMENTS FOR EXTERNAL PROCEDURES

Actual arguments specify the entities to be associated with the dummy arguments of a referenced subroutine or external function.

The actual arguments in a reference to an external procedure must agree in order, number, and type with the dummy arguments in the procedure or procedure entry. CFT77 does not enforce agreement in number, and you can omit later arguments if you know that the corresponding dummy arguments will not be referenced (non-ANSI). An actual argument can be a

subroutine name or an alternate return specifier (see 2.5.3.2); these do not have data types, so the requirement for type agreement does not apply.

An actual argument in an external procedure reference must be one of the following. (See 2.4.3.1 and 2.4.2 concerning actual arguments for

intrinsic functions and statement functions.)

Expressions: Any expression other than a) an array syntax expression or b) a character expression with an operand whose length is specified as (*), unless the operand is the name of a constant (see 3.7.3). If the expression includes an operator or parentheses, i t is evaluated and stored in a temporary variable, which is then associated with the dummy argument. The following kinds of expressions involve these considerations:

Array element or substring name. The array subscript or substring designator is evaluated just before the arguments are associated, and i t remains constant as long as the

arguments are associated, even if the subscript or designator contains variables that are redefined during the association.

Function reference has its own argument list (empty where

Procedure name. The name of an intrinsic function, external

function, or subroutine. This allows a called procedure to call a second procedure that is specified in the first call (see 2.6.4).

Array name. The referenced actual array must be at least as large as the dummy array in the called procedure (see 4.3.6.1 and 4.3.7).

Alternate return specifier (subroutines only): A specifier of the form *n, where n is a statement label in the calling program

unit (see 2.5.3.2).

Dummy argument within the same subprogram that is making the procedure call. Example:

CALL SUBA(X)

SUBROUTINE SUBA(Y) CALL SUBB(Y)

SUBROUTINE SUBB(Z)

Variable Y above serves as a dummy argument within subroutine SUBA, but is used as an actual argument in the call to subroutine SUBB. This allows a value to be passed through several levels of procedures. (Alternate return specifiers cannot be used this way.)

2.6.3 DUMMY ARGUMENTS

Subprograms use dummy arguments to indicate the types of actual arguments and whether each is a single value, an array, or a procedure. A

reference to a subprogram causes its dummy arguments to become defined if the corresponding actual arguments are defined. A dummy argument name is local to a subprogram. Dummy arguments have the following requirements:

Specify before using: If a dummy argument is referenced in an executable statement or statement function statement, i t must be specified within the subprogram's header statement or a preceding ENTRY statement; or as a dummy argument within the same statement function statement.

Kinds of dummy arguments: Each dummy argument is classified as a variable, array, or procedure. A dummy argument that is a

variable can be associated with an actual argument that is a variable, array element, substring, or expression.

Prohibited statements: A dummy argument name cannot appear in an EQUIVALENCE, DATA, SAVE, INTRINSIC, or PARAMETER statement, as a pointee in a POINTER statement, or in a COMMON statement (except as a common block name).

• Name duplication: A dummy argument name in a subprogram must not be the subprogram's name or the name of a statement function in the subprogram.

• Dummy array declarators: Adjustable dimension declarators can contain dummy arguments of type integer.

• Statemept function dummy arguments must have scalar values (see 4.2).

Dans le document CRAY® COMPUTER SYSTEMS (Page 92-95)