[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1.6.2 The Function

 
function function identifier: function result type;
declaration part
begin
  statement part
end;
or with a parameter list:
 
function function identifier (parameter list): funcion result type;
declaration part
begin
  statement part
end;

A function is a subroutine which has a return value of type function result type. It is structured like the program: the declaration part consists of label, constant, type, variable or subroutine declarations in free order. The statement part consists of a sequence of statements. If parameter list is specified, parameters can be passed to the function and can be used in statement part. The return value is set via an assignment:
 
function identifier := expression
Recursive function calls are allowed. Concerning the result type, ISO-7185 Pascal and Borland Pascal only allow the intrinsic types, subranges, enumerated types and pointer types to be returned. In Extended Pascal, function result type can be every assignable type. Of course, there are no type restrictions in GNU Pascal as well. If extended syntax is switched on, functions can be called like procedures via procedure call statement.

See also

section 8.1.6.1 The Procedure, section 8.1.6.4 Subroutine Parameter List Declaration, section 8.2 Data Types



This document was generated by Frank Heckenbach on May, 10 2002 using texi2html