TAL Programmer's Guide
Declaring Data in Procedures
Using Procedures
11–4 096254 Tandem Computers Incorporated
Passing Actual Parameters The formal parameter declarations in the called procedure dictates how the calling
procedure declares the actual parameters. For example, if the called procedure
declares a simple variable as a formal reference parameter, the calling procedure must
declare a simple pointer as the actual parameter.
The calling procedure passes actual parameters by specifying an actual parameter list
in a CALL statement. In the following example, PROC_Y calls PROC_X (declared in
the previous example). PROC_Y passes VAR1 by value and VAR2 by reference as
dictated by the formal parameter declarations in PROX_X:
PROC proc_y; !Declare PROC_Y
BEGIN
INT var1 := 50; !Declare simple variable
INT .var2 := 20; !Declare simple pointer
CALL proc_x (var1, var2); !Call PROC_X and pass
END; !actual parameters to it
When a CALL statement occurs, the compiler assigns each actual parameter to a
formal parameter in order. More information on parameters is provided in “Using
Parameters” later in this section.
Declaring Data
in Procedures
Data items you declare before the first procedure declaration have global scope. You
can access global data from any procedure in the program.
Data items you declare within a procedure have local scope. You can access local data
only from within the same procedure.
A local data item can have the same identifier as a global data item. In this case,
however, you cannot access the global data item from within that procedure. For
example, if you declare global variables A and B and local variables A and B, the
procedure can access local variables A and B but not global variables A and B. If you
declare a variable named C only at the global level, the procedure can access C:
INT a := 9; !Declare global A, B, and C
INT b := 3;
INT c;
PROC a_proc MAIN; !Declare A_PROC
BEGIN
INT a := 4; !Declare local A and B
INT b := 1;
c := a + b; !Access local A and B
END; !End A_PROC