Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> forward forward declaration pp 145</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 FORWARD                     Forward Declaration                      pp 145

 Syntax:  Forward

 Type:    N/A

 Form:    Declaration

 Purpose: Enable usage of a function or procedure before it is declared.

 Notes:   A subroutine is Forward declared by specifying its heading
          separately from the code block.  This separate heading is exactly
          the same as the the normal heading except that it is terminated by
          the reserved word Forward.

          The code block follows later within the same declaration part.
          This code block will be initiated by a copy of the heading using
          the name only.  No parameters or types will be given.


 Usage:
       PROGRAM
          Crash                          ;      { Program will crash        }

       VAR
          Alpha : Integer                ;      { Test argument             }

       Procedure Test2 (var A : Integer) ; Forward ;
       Procedure Test1 (var A : Integer) ;
          Begin
          If A > 0 then Test2 (A)        ;      { Non-Forward compile fails }
          End                            ;

       Procedure Test2                   ;      { New declaration           }
    (* Procedure Test2 (var A : Integer) ; *)   { Deleted by Forward        }
          Begin
          If A > 0 then Test1 (A)        ;      { Recurse until you crash   }
          End                            ;

       BEGIN                             ;      { Main line code            }
          Alpha := 15                    ;      { Assign argument           }
          Test1 (Alpha)                  ;      { Call recursion            }
       END.                              ;      { End of main line          }

See Also: Function Procedure

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson