## 8.8.1 Optional Arguments

Dummy arguments can be made optional if they are declared with the OPTIONAL attribute. In this case, an actual argument does not have to be supplied for it in a procedure reference.

Positional arguments (if any) must appear first in an actual argument list, followed by keyword arguments (if any). If an optional argument is the last positional argument, it can simply be omitted if desired.

However, if the optional argument is to be omitted but it is not the last positional argument, keyword arguments must be used for any subsequent arguments in the list.

Optional arguments must have explicit procedure interfaces so that appropriate argument associations can be made.

The PRESENT intrinsic function can be used to determine if an actual argument is associated with an optional dummy argument in a particular reference.

The following example shows optional arguments:

    PROGRAM RESULT
    TEST_RESULT = LGFUNC(A, B=D)
    ...
    CONTAINS
      FUNCTION LGFUNC(G, H, B)
        OPTIONAL H, B
        ...
      END FUNCTION
    END

In the function reference, A is a positional argument associated with required dummy argument G. The second actual argument D is associated with optional dummy argument B by its keyword name (B). No actual argument is associated with optional argument H.

For More Information:

- On general rules for procedure argument association, see Section 8.8.
- On the OPTIONAL attribute, see Section 5.13.
- On argument keywords in subroutine references, see Section 7.2.
- On argument keywords in function references, see Section 8.5.2.2.
- On the PRESENT intrinsic function, see Section 9.3.118.

Previous Page Next Page Table of Contents