TAL Programmer's Guide
Declaring Procedures
Structuring Programs
3–6 096254 Tandem Computers Incorporated
Declaring Procedures You declare procedures to define routines that are callable from routines in any
compilation unit in the program. You can declare procedures that perform discrete
operations such as I/O or error handling. Normally, a procedure declaration includes
a procedure heading and a procedure body.
Procedure Heading For the procedure heading, include the following:
The keyword PROC
The procedure identifier
Identifiers of formal parameters, if any
Procedure attributes, if any
Declarations of formal parameters, if any
A procedure heading that has no formal parameters or attributes looks like this:
PROC my_heading;
The following procedure heading has one parameter (named PARAM) and the MAIN
attribute. MAIN means execute this procedure first. The second line declares the
formal parameter as being of data type INT:
PROC my_proc (param) MAIN;
INT param;
A function is a procedure that returns a value to the caller. You declare a function as
you do any other procedure except that in the function heading you specify a data
type for the return value. Here is a function heading that specifies a return data type
of INT:
INT PROC my_function (param);
INT param;
Procedure Body The procedure body is a BEGIN-END construct that can contain local data
declarations, subprocedure declarations, and local statements. Here is an example:
PROC myproc;
BEGIN
INT var1; !Local data declarations
INT var2;
!Some code here
var1 := var1 - var2; !Local assignment statement
END;
FORWARD Procedures If you need to call a procedure before you declare the procedure body, first declare a
procedure heading that includes the FORWARD keyword. Once you declare a
FORWARD procedure, you can call the procedure from anywhere in the current
compilation unit. For example, you can declare a FORWARD procedure named
TO_COME like this:
PROC to_come;
FORWARD;