TAL Reference Manual
Standard Functions
TAL Reference Manual—526371-001
14-31
Usage Considerations
Usage Considerations
The zeroth structure occurrence has an offset of 0. For items other than a structure
data item, $OFFSET returns a 0.
When you qualify the identifier of
variable, you can use constant indexes but not
variable indexes; for example:
$OFFSET (struct1.subst[1].item) !1 is a constant index
For a structure pointer declared inside a structure, $OFFSET computes the byte offset
of the structure occurrence to which the pointer points, not the byte offset of the
structure pointer itself. When you specify such a pointer as an argument to $OFFSET,
you must qualify its identifier with the identifier of the structure data item (see Example
2).
For UNSIGNED structure items, $OFFSET returns the byte offset of the nearest word
boundary, not the nearest byte boundary.
You can use $OFFSET in LITERAL expressions and global initializations, because it
always returns a constant value.
If you apply $OFFSET to an unfinished structure or to a substructure in an unfinished
structure, the compiler emits warning 76 (cannot use $OFFSET or $LEN until base
structure is complete).
Examples of $OFFSET Function
1. In this example, $OFFSET returns the byte offset of the third occurrence of a
substructure from the address of the zeroth structure occurrence:
STRUCT a; !Declare structure
BEGIN
INT array[0:40];
STRUCT ab[0:9]; !Declare substructure AB
BEGIN ! with ten occurrences
!Lots of declarations
END;
END;
INT c;
!Some code
c := $OFFSET (a.ab[2]); !Return offset of third
! occurrence of substructure
2. In this example, $OFFSET returns the byte offset of the structure occurrence to
which a structure pointer points:
STRUCT .tt; !Declare structure TT
BEGIN
INT i;
INT(32) d;