HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
FUNCTION
Chapter 10 363
FUNCTION
Introduces a function subprogram.
Syntax
[RECURSIVE] [
type-spec
] FUNCTION
function-name
([
dummy-arg-name-list
])
[RESULT (
result-name
)]
RECURSIVE
is a keyword that must be specified in the FUNCTION statement if the
function is either directly or indirectly recursive. The RECURSIVE clause can
appear at most once, either before or after
type-spec
. It is not an error to
specify RECURSIVE for a nonrecursive function.
A recursive function that calls itself directly must also have the RESULT
clause specified (see below).
type-spec
is a valid type specification (INTEGER, REAL, LOGICAL, CHARACTER, TYPE
(
name
), etc.). The type and type parameters of the function result can be
specified by
type-spec
or by declaring the result variable within the
function subprogram, but not by both. The implicit typing rules apply if the
function is not typed explicitly.
If the function result is array-valued or a pointer, the appropriate attributes
for the result variable (which is
function-name
, or
result-name
if
specified) must be specified within the function subprogram.
function-name
is the name of the function subprogram being defined.
dummy-arg-name-list
is a comma-separated list of dummy argument names for the function.
result-name
is the result variable. If the RESULT clause is not specified,
function-name
becomes the result variable. If
result-name
is given, it must differ from
function-name
, and
function-name
must not then be declared within the
function subprogram.