TAL Programmer's Guide
Declaring and Calling Subprocedures
Using Procedures
11–18 096254 Tandem Computers Incorporated
Sublocal Parameter
Storage Limitations
The order in which a subprocedure passes parameters could result in a range violation
error. The error occurs when an actual parameter of the subprocedure refers to a
sublocal variable located beyond S[–31] in the caller’s sublocal storage area.
The following example shows two subprocedure calls. The first call passes actual
parameters in reverse order, causing an error:
PROC my_proc MAIN;
BEGIN
!Lots of local declarations
SUBPROC sub1 (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s);
INT a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;
BEGIN
END;
SUBPROC sub2;
BEGIN
INT A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S;
CALL sub1 (
S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A
);
!Cause error
CALL sub1 (
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S
);
!No error
END; !Actual parameters are shown in italics to
!distinguish them from variables in the text.
!Lots of code
END;
In effect, here is what happens: When SUB2 is activated, the compiler allocates each
variable at location S[0] in the order declared (from A through S) and pushes
preceding variables to increasingly negative offsets from S[0]. Part 1 of Figure 11-2
shows the sublocal allocation immediately after activation of SUB2.
The first time SUB2 calls SUB1, SUB2 passes parameters in reverse order from the
order of the variables. The compiler allocates each actual parameter at S[0], in the
order specified (from S through A) and pushes preceding variables and parameters
away from S[0]. Each parameter (when allocated at S[0]), must access the
corresponding variable to receive its value. For example, parameter S must receive the
value stored in variable S, and so on. When parameter D is allocated at S[0], variable
D is allocated at S[–31] and is still accessible. When parameter C is allocated at S[0],
however, variable C is pushed beyond S[–31], is not accessible, and an error results.
Part 2 of Figure 11-2 shows sublocal allocation at the point at which the error occurs.
The second time SUB2 calls SUB1, SUB2 passes parameters in the same order as the
variables, so each variable is accessible when the corresponding parameter is allocated
at S[0]. Part 3 of Figure 11-2, shows that every variable is accessible when the
corresponding parameter is allocated at S[0].