TAL Programmer's Guide
Using Standard Functions With Structures
Using Structures
096254 Tandem Computers Incorporated 8–43
Using Standard
Functions With
Structures
You can use the following standard functions with structures. These functions return
information such as the length of a structure occurrence or the offset of a structure
item within a structure:
Standard Function Effect
$BITLENGTH Returns the length, in bits, of one occurrence of a structure or substructure
$BITOFFSET Returns an item’s offset, in bits, from the zeroth occurrence of the
encompassing structure
$LEN Returns the length, in bytes, of one occurrence of an item
$OFFSET Returns an item’s offset, in bytes, from the zeroth occurrence of the
encompassing structure
$OCCURS Returns the number of occurrences of a structure, substructure, or array, but
not of a template structure
$TYPE Returns the type of an item
The following example reads structured data from a disk file. In the FOR statement,
$OCCURS returns 6 (the number of occurrences in JOB_DATA), and $LEN returns 24
(the length in bytes of one occurrence of JOB_DATA):
INT record_num; !Number of records
STRUCT emp_data(
*
); !Template structure
BEGIN
INT number;
INT dept;
STRING ssn[0:11];
FIXED(2) salary;
END;
PROC p MAIN; !Main procedure
BEGIN
INT diskfile, num_read;
STRUCT .job_data (emp_data) [0:5]; !Referral structure
!Some code
FOR record_num := 0 TO $OCCURS (job_data) - 1 DO
!FOR statement
CALL READ(diskfile, !CALL statement
job_data[record_num], !Buffer
$LEN (job_data), !Maximum bytes to read
num_read); !Count of bytes read
!More code
END;
In the preceding example, the FOR statement calls the READ system procedure once
for each occurrence of structure JOB_DATA. For information on the READ procedure,
see the Guardian Procedure Calls Reference Manual.