TAL Programmer's Guide

Using Read-Only Arrays
Using Arrays
7–24 096254 Tandem Computers Incorporated
Using Read-Only
Arrays
A read-only array is an array you cannot modify. When you declare a read-only array,
the compiler allocates storage for the array in a user code segment.
Declaring
Read-Only Arrays
Read-only array declarations differ from other array declarations in a number of ways:
You must specify the read-only array symbol (= 'P') following the array identifier.
You must initialize read-only arrays when you declare them, because you cannot
assign values to read-only arrays by using assignment statements later in your
program.
You cannot declare read-only arrays of data type UNSIGNED because you cannot
initialize UNSIGNED arrays.
You cannot declare indirect read-only arrays, because code segments have no
primary or secondary storage areas.
You can omit the array bounds. The default lower bound is 0; the default upper
bound is the number of elements initialized minus one.
For example, you can declare and initialize two read-only arrays, PROMPT and
ERROR, using default bounds:
STRING prompt = 'P' := ["Enter a character: ", 0];
INT error = 'P' := ["Incorrect input"];
Numeric constants in the constant list should be appropriate for the data type of the
array.
The system uses the program counter (P register) to access read-only arrays. The P
register contains the address of the next instruction to be executed in the current code
segment.
If you declare a read-only array in a procedure declared with the RESIDENT
procedure attribute, the array is also resident in main memory. For more information
on the RESIDENT attribute of procedures, see the TAL Reference Manual.
Accessing
Read-Only Arrays
You can access read-only arrays in the same way as you access any other array, except
that:
You cannot modify a read-only array; that is, you cannot specify a read-only array
on the left side of an assignment or move operator.
You cannot specify a read-only array on the left side of a group comparison
expression.
In a SCAN or RSCAN statement, you cannot use next-address to read the last
character of a string. You can use next-address to compute the length of the string.
A procedure can access any global read-only array located in the same 32K-word area
of the code segment.