The forward directive specifies that the current function or procedure declaration is incomplete (the function or procedure block is omitted).
Example
The following simple example illustrates how to use the forward directive.
program forward(output);
procedure display(message : string); forward;
procedure DisplayHello;
begin
display('Hello');
end;
procedure display;
begin
writeln(message)
end;
begin
DisplayHello;
end.
NOTE: There ar two declarations for the procedure display. The first declaration for display uses the forward and omits the procedure block but declares the formal parameter message. The second declaration for display includes the procedure block which references the formal parameter message even though message is not declared in the second declaration. It would be an error or declare the formal parameter in the second declaration of display.
Syntax
The syntax for declaring forward functions and procedures is give below (NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):
function-declaration = function-heading ';' forward-directive
procedure-declaration = procedure-heading ';' forward-directive
forward-directive = 'forward'
function-heading = 'function' identifier [ formal-parameter-list ] ':' result-type
procedure-heading = 'procedure' identifier [ formal-parameter-list ]
result-type = type-identifier
A second declaration for the function or procedure must appear later on in the program with the function or procedure block included but the formal parameter list omitted. The syntax for the second declaration of the function or procedure is given below (NOTE: for clarity some parts of the syntax are omitted, see Irie Pascal Grammar for the full syntax):
function-declaration = function-identification ';' function-block
procedure-declaration = procedure-identification ';' procedure-block
block = declarative-part statement-part
declaration-group =
label-declaration-group |
constant-definition-group |
type-definition-group |
variable-declaration-group |
function-declaration |
procedure-declaration
declarative-part = { declaration-group }
function-block = block
function-identifier = identifier
procedure-block = block
procedure-identifier = identifier