5.13 OPTIONAL Attribute and Statement

The OPTIONAL attribute permits dummy arguments to be omitted in a procedure reference.

The OPTIONAL attribute can be specified in a type declaration statement or an OPTIONAL statement, and takes one of the following forms:

Type Declaration Statement:

 type, [att-ls,] OPTIONAL [,att-ls] :: d-arg [,d-arg]...

Statement:

 OPTIONAL [::] d-arg [,d-arg]...
type
Is a data type specifier.
att-ls
Is an optional list of attribute specifiers.
d-arg
Is the name of a dummy argument.

Rules and Behavior

The OPTIONAL attribute can only appear in the scoping unit of a subprogram or an interface body, and can only be specified for dummy arguments.

A dummy argument is "present" if it associated with an actual argument. A dummy argument that is not optional must be present. You can use the PRESENT intrinsic function to determine whether an optional dummy argument is associated with an actual argument.

Examples

The following example shows a type declaration statement specifying the OPTIONAL attribute:

SUBROUTINE TEST(A)
REAL, OPTIONAL, DIMENSION(-10:2) :: A
END SUBROUTINE

The following is an example of the OPTIONAL statement:

SUBROUTINE TEST(A, B, L, X)
   OPTIONAL :: B
   ...
   IF (.NOT. PRESENT(B)) THEN
      B = 1.0
   END IF

For More Information:


Previous Page Next Page Table of Contents