next up previous contents
Next: Function Example Up: External Procedures Previous: External Subroutine Example

 

External Function Syntax

Syntax of a (non-recursive) function:

 
 [< prefix >] FUNCTION < procname >( [< dummy args >])

< declaration of dummy args >

< declaration of local objects >

...

< executable stmts, assignment of result >

[ CONTAINS

< internal procedure definitions > ]

END [ FUNCTION [ < procname > ] ]

here < prefix >, specifies the result type. or,
 
 FUNCTION < procname >( [< dummy args >])

< declaration of dummy args >

< declaration of procname type >

< declaration of local objects >

...

< executable stmts, assignment of result >

[ CONTAINS

< internal procedure definitions > ]

END [ FUNCTION [ < procname > ] ]

Functions are very similar to subroutines except that a function should have a type specifier which defines the type of the result. (The type of the function result can either be given as a prefix to the function name or alternatively be given in the declarations area of the code by preceding the function name (with no arguments or parentheses) by a type specifier. It is a matter of personal taste which method is adopted.) For example,

    INTEGER FUNCTION largest(i,j,k)
     IMPLICIT NONE

is equivalent to,

    FUNCTION largest(i,j,k)
     IMPLICIT NONE 
     INTEGER largest

The function name, < procname >, is the result variable so a function must contain a statement which assigns a value to this name; a routine without one is an error.

The type of an external function must be given in the calling program unit. It is good practise to attribute this declaration with the EXTERNAL attribute. A valid declaration in the calling program unit might be,

    INTEGER, EXTERNAL :: largest

Return to corresponding overview page gif




next up previous contents
Next: Function Example Up: External Procedures Previous: External Subroutine Example

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.