pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Global structure pointers receive their initial values when you compile the source code. Local and
sublocal structure pointers receive their initial values each time the procedure or subprocedure is
activated.
Example 116 Declaring and Initializing a Structure Pointer, Using $OFFSET
STRUCT t (*); ! Template structure
BEGIN
INT k;
END;
STRUCT .st; ! Definition structure
BEGIN
INT j;
STRUCT ss (t);
END;
INT .ip := @st '+' $OFFSET (st.j) '>>' 1; ! Simple pointer
INT .stp (t) := @st '+' $OFFSET (st.ss) '>>' 1;
! INT structure pointer
STRING .sstp (t) := @st '<<' 1 '+' $OFFSET (st.ss);
! STRING structure pointer
A standard STRING structure pointer can access only these structure items:
Substructure
STRING simple variable
STRING array
The last declaration in Example 116 (page 175) shows a STRING structure pointer initialized with
the converted byte address of a substructure.
Example 117 (page 175) shows another way to access a STRING item in a structure. You can
convert the word address of the structure to a byte address when you initialize the STRING structure
pointer and then access the STRING item in a statement.
Example 117 Declaring and Initializing a STRING Structure Pointer
STRUCT .astruct[0:1];
BEGIN
STRING s1;
STRING s2;
STRING s3;
END;
STRING .ptr (astruct) := ! STRING ptr initialized with converted
@astruct[1] '<<' 1; ! byte address of astruct[1].
ptr.s2 := %4; ! Access STRING structure item
Example 118 Declaring and Initializing a Local Structure Pointer
PROC my_proc MAIN;
BEGIN
STRUCT my_struct[0:2];
BEGIN
INT array[0:7];
END;
INT .struct_ptr (my_struct) := @my_struct[1];
! Structure pointer contains address of my_struct[1]
END;
Example 119 Declaring and Initializing a Local STRING Structure Pointer
STRUCT name_def(*);
BEGIN
Initializing Structure Pointers 175