[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
FUNCTION Declaring and Using a Function pp 137
Syntax: Function Name (Formal Parm List) : Type ;
Type: Scalar, String, or Pointer
Form: Declaration
Purpose: A function defines a subroutine. It may be either pre-declared
as a part of the TURBO system, or user declared as defined by
the programmer. The intent of a function is to return a result.
The reserved word 'Function' is followed by an identifer which
becomes the name of the function, optionally followed by a
list of formal parameters. Type identifies the returned result.
All identifiers in the formal parameter list and the declaration
part of the function are local to the function.
These identifiers are not visible outside the function.
This is termed the scope of the identifier.
Parms: The formal parameters are used to define the function. The
names assigned to them are only identifiers, not actual variables.
The formal parameters only identify the number and type of
variables that will be used by the function.
Define: Function SQUARE (NumVar) : Real ;
Usage: Number := SQUARE (200) ;
This example indicates to the compiler that when SQUARE is called
it will be called with one parameter of type Real.
Types: Formal parameters can be of two types: Value or Variable.
Value parameters are constants or actual values of variables.
The SQUARE function uses Value parameters in the example.
A constant is passed as a value parameter when the above
function is called.
Variable parameters are the actual addresses of the variables.
The variables passed when the function is called will be
acted upon by the function.
Define: Function SQUARE (VAR Dummy1 : Integer) : Real ;
Begin
Dummy1 := Dummy1 * Dummy1 { Square the number }
End;
Usage: Squared_Number := SQUARE (IntVar) ;
Dummy1 is a Variable formal parameter. It indicates to the
compiler that when SQUARE is called, the parm passed with the
function will be the actual variable address.
The variable will then be acted upon by the function.
See Also:
External
Forward
Inline
Procedure
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson