pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-18
Incrementing and Decrementing Pointers
You can use indexing whenever the number of elements you are stepping is an integral
multiple of the size of an array element, including structure arrays. The following
example shows how you can step across k array elements:
@wp := @wp[k];
In Example 2-13 on page 2-18, the pointer p points to the beginning of the structure,
not to the required field in the structure. You can still use indexing to reference the
same field in the next element of array s.
Example 2-12. Incrementing a Pointer
STRUCT .s[0:9];
BEGIN
INT i;
INT(32) j;
INT k;
STRING l;
END;
INT .p(s) := @s;
@p := @p '+' 5; ! Must know size of s
@p := @p '+' $LEN(s)/2; ! Need not know size of s, but complex
@p := @p[1]; ! Need not know size of s, simpler
Example 2-13. Incrementing a Pointer by Indexing
STRUCT s[0:9];
BEGIN
INT i;
INT j;
INT val;
END;
INT .p(s);
@p := @s; ! Point to 1st array element
WHILE p.val <> 0 DO ! Test VAL field
@p := @p[1]; ! Index to start of next array elem
! The following three statements perform the same function as
! the previous three but are somewhat faster
@p := @s.val; ! Point to VAL field of 1st array element
WHILE p <> 0 DO ! Test VAL field
@p := @p[1]; ! Index to VAL field of next array elem