TAL Programmer's Guide
Using Standard Functions With Arrays
Using Arrays
096254 Tandem Computers Incorporated 7–23
Comparing Arrays You can compare two arrays, or compare an array to a constant list, by using a group
comparison expression in a statement. Group comparison expressions are described in
Section 13, “Using Special Expressions.” Here are some examples.
You can compare an array to a constant list:
STRING an_array[0:3]; !Declare array
!Some code here
IF an_array[0] = ["ABCD"] THEN ... ; !Compare array to
! constant list
You can compare two arrays:
INT in_array[0:8]; !Declare array
INT out_array[0:8]; !Declare array
!Some code here
IF in_array = out_array FOR 9 ELEMENTS THEN ... ;
!Compare the arrays
You can use the next address in a group comparison expression:
STRING .sp; !Declare next-address
! pointer
STRING .a[0:1] := "AB"; !Declare array
STRING .b[0:1] := "AC"; !Declare array
IF b <> a FOR 2 BYTES -> @SP THEN ... ; !SP points to B[1]
Using Standard
Functions With Arrays
You can use the following standard functions to get certain information about arrays,
such as the number of elements in an array:
Standard Function Effect
$BITLENGTH Returns the length, in bits, of one array element
$LEN Returns the length, in bytes, of one array element (1 for STRING arrays, 2
for INT arrays, and so forth)
$OCCURS Returns the number of elements in an array
$TYPE Returns a value that denotes the data type of an array
For example, you can find the total length of an array as follows:
INT array_length;
INT array[0:2];
array_length := $LEN (array) * $OCCURS (array);