[next] [prev] [prev-tail] [tail] [up]

### 8.5 Forward defined functions

A function can be declared without having it followed by it’s implementation, by having it followed by the forward procedure. The effective implementation of that function must follow later in the module. The function can be used after a forward declaration as if it had been implemented already. The following is an example of a forward declaration.

     Program testforward;
     Procedure First (n : longint); forward;
     Procedure Second;
     begin
       WriteLn ('In second. Calling first...');
       First (1);
     end;
     Procedure First (n : longint);
     begin
       WriteLn ('First received : ',n);
     end;
     begin
       Second;
     end.

A function can be defined as forward only once. Likewise, in units, it is not allowed to have a forward declared function of a function that has been declared in the interface part. The interface declaration counts as a forward declaration. The following unit will give an error when compiled:

     Unit testforward;
     interface
     Procedure First (n : longint);
     Procedure Second;
     implementation
     Procedure First (n : longint); forward;
     Procedure Second;
     begin
       WriteLn ('In second. Calling first...');
       First (1);
     end;
     Procedure First (n : longint);
     begin
       WriteLn ('First received : ',n);
     end;
     end.

[next] [prev] [prev-tail] [front] [up]