# General Rules for Function and Subroutine Subprograms

A subprogram can be an external, module, or internal subprogram. The END statement for an internal or module subprogram must be END SUBROUTINE [name] for a subroutine, or END FUNCTION [name] for a function. In an external subprogram, the SUBROUTINE and FUNCTION keywords are optional.

If a subprogram name appears after the END statement, it must be the same as the name specified in the SUBROUTINE or FUNCTION statement.

Function and subroutine subprograms can change the values of their arguments, and the calling program can use the changed values.

A SUBROUTINE or FUNCTION statement can be optionally preceded by an OPTIONS statement.

Dummy arguments (except for dummy pointers or dummy procedures) can be specified with an intent and can be made optional.

Subroutines and functions are by default assumed to be non-recursive. This can be changed by declaring the function RECURSIVE, either with the RECURSIVE keyword on the SUBROUTINE or FUNCTION statement, or by specifying an option on the command line or in an OPTIONS statement. The Fortran 2018 Standard specifies that the default mode of compilation is recursion; prior standards specified non-recursion. Fortran 2018 behavior can be achieved by specifying the assume recursion or the standard-semantics option on the command line.

## See Also

RECURSIVE procedures
PURE procedures
User-defined ELEMENTAL procedures
Module procedures
Internal procedures
External procedures
Optional arguments
INTENT attribute
standard-semantics compiler option
assume recursion compiler option