Top: f77 Up: 13 - Statements
Previous: 13,32 - FORMAT Next: 13,34 - Function_Reference


Section 13,33: FUNCTION

 Begins a function subprogram.  Identifies the data type of the
 function and names the dummy arguments.  Format:

    [typ] FUNCTION nam [*m][([p[,p]...])]

    typ  Is a data type.  If you do not specify a data type, 
         the data type of the function is implied from its 
         name.  If the data type is CHARACTER, you can specify 
         CHARACTER*(*) to indicate a passed length function
         type -- the function type assumes the length of its 
         definition in the program unit invoking it.

    nam  Is a symbolic name for the function.  The name must be 
         unique among all global names in the program.  The name 
         is used as a variable within the function.  The value of 
         the variable is returned to the caller of the function 
         as the value of the function.

    m    Is an unsigned, nonzero integer specifying the length of
         the data type. It must be one of the valid length specifiers
         for "typ".  This length overrides the length specified or 
         implied by the type.

    p    Is an unsubscripted variable name specifying a dummy 
         argument.  The arguments must agree in order, number, and 
         type with the actual arguments of the statement invoking 
         the function.  A dummy argument must not be defined as an 
         array with more elements than the actual argument holds.

 The array declarator for a dummy argument can itself contain
 integer values that are dummy arguments or are references to a
 common block, providing for adjustable size arrays in functions.
 The upper bound of the array declarator for a dummy argument can be
 specified as an asterisk, in which case the upper bound of the
 dummy argument assumes the size of the upper bound of the actual
 argument.  The size in a character string declarator for a dummy
 argument can be specified as an asterisk in parentheses (*) -- in
 which case the size of the actual argument is passed to the dummy
 argument.

 The values of the actual arguments in the invoking program unit
 become the values of the dummy arguments in the function.  If you
 modify a dummy argument, the corresponding actual argument in the
 invoking program unit is also modified; the actual argument must be
 a variable if it is to be modified.

 If the actual argument is a character constant, the dummy argument
 can be either character or numeric in type, unless the name of the
 subprogram being invoked is a dummy argument in the invoking
 program unit.  If the actual argument is a Hollerith constant, the
 dummy argument must be numeric.

 The FUNCTION statement must be the first statement of a function
 subprogram, unless an OPTIONS statement is specified.  A function
 subprogram cannot contain a SUBROUTINE statement, a BLOCK DATA
 statement, a PROGRAM statement, or another FUNCTION statement.
 ENTRY statements can be included to provide multiple entry points
 to the subprogram.

                                NOTE

         In a function, the function name identifier  refers
         to  the  return  value,  not  the  function itself,
         unless an argument list is present.  Therefore,  it
         is  not  possible to pass a function as an argument
         to another routine from inside the  function.   For
         example, consider the following:

            INTEGER FUNCTION RECURSIVE_FUNCTION
               . 
               .
               .
            CALL OTHERSUB (RECURSIVE_FUNCTION)

         The reference to  RECURSIVE_FUNCTION  in  the  CALL
         statement passes the function return value, not the
         function itself.


Top: f77 Up: 13 - Statements
Previous: 13,32 - FORMAT Next: 13,34 - Function_Reference