CALL

Purpose

The CALL statement invokes a subroutine to execute.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-CALL--+-name-----------------------------------+------------->
         |                         (1)            |   
         +-procedure_component_ref----------------+   
         |          (2)                           |   
         '-data_ref------separator-- binding_name-'   

>--+-------------------------------------+---------------------><
   '-(--+---------------------------+--)-'   
        '-actual_argument_spec_list-'        

Notes:
  1. Fortran 2003
  2. Fortran 2003
name
The name of an internal, external, or module subroutine, an entry in an external or module subroutine, an intrinsic subroutine, a generic name, or a procedure pointer.
procedure_component_ref
The name of a procedure pointer component of the declared type of data_ref. For details, see Procedure pointer components.
data_ref
The name of an object of derived type
separator
is % or .
binding_name
is the name of a procedure binding of the declared type of data_ref

Rules

Executing a CALL statement results in the following order of events:
  1. Actual arguments that are expressions are evaluated.
  2. Actual arguments are associated with their corresponding dummy arguments.
  3. Control transfers to the specified subroutine.
  4. The subroutine is executed.
  5. Control returns from the subroutine.

A procedure pointer is a pointer that is associated with a procedure. Procedure pointers may have either an explicit or implicit interface and the interface may not be generic or elemental.

If the binding_name in a procedure designator is that of a specific procedure, the procedure referenced is the one identified by the binding with that name in the dynamic type of the data_ref. If the binding_name in a procedure designator is that of a generic procedure, the generic binding with that name in the declared type of the data_ref is used to select a specific binding according to the following rules:
  1. If the reference is consistent with one of the specific bindings of that generic binding, that specific binding is selected.
  2. Otherwise, if the reference is consistent with an elemental reference to one of the specific bindings of that generic binding, that specific binding is selected.
The reference is to the procedure identified by the binding with the same name as the selected specific binding, in the dynamic type of the data_ref.

A subprogram can call itself recursively, directly or indirectly, if the subroutine statement specifies the RECURSIVE keyword.

If a CALL statement includes one or more alternate return specifiers among its arguments, control may be transferred to one of the statement labels indicated, depending on the action specified by the subroutine in the RETURN statement.

An external subprogram can also refer to itself directly or indirectly if the -qrecur compiler option is specified.

The argument list built-in functions %VAL and %REF are supplied to aid interlanguage calls by allowing arguments to be passed by value and by reference, respectively. They can only be references to non-Fortran procedures.

The VALUE attribute also allows you to pass arguments by value.

Examples

INTERFACE
  SUBROUTINE SUB3(D1,D2)
    REAL D1,D2
  END SUBROUTINE
END INTERFACE
ARG1=7 ; ARG2=8
CALL SUB3(D2=ARG2,D1=ARG1)    ! subroutine call with argument keywords
END

SUBROUTINE SUB3(F1,F2)
  REAL F1,F2,F3,F4
  F3 = F1/F2
  F4 = F1-F2
  PRINT *, F3, F4
END SUBROUTINE


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us