Offset Data

The OFFSET attribute describes a locator data type that is used to specify the location of a based variable within an area. The format of the OFFSET attribute is:

OFFSET [(area-variable)]

An offset variable is a locator used only in conjunction with an area variable. The value of an offset variable specifies the location of a based variable within an area, relative to the beginning of the area. Since an offset value specifies a relative location, the value remains valid even when the area is assigned to another region of storage.

To use an offset variable to identify a particular based variable, the offset variable must be associated with an area. For example:

DECLARE A   AREA,
        O   OFFSET(A),
        X   FIXED BASED(O),
        Z   OFFSET,
        P   POINTER;

ALLOCATE X IN(A) SET(O);
X = 5;                  /* Implies area and offset */

This association can be done in the declaration by specifying the area variable, as shown in the previous example. This type of declaration has the convenience of implicitly referring to the associated area whenever a reference is made to the offset variable used as a locator.

When an offset value is assigned to or compared with another offset variable, only its actual value is used — the implicit area reference is ignored. However, when used as a locator, or when compared to or assigned to a pointer, the offset value is implicitly converted to a pointer by generating an address derived from the offset value combined with the address of the area with which it is associated. If this association was not done in the declaration, it can still be done using the POINTER built-in function:

P = POINTER(Z, A);   /* offset Z was not associated with
                           area A in its declaration */

Note that, if the offset variable did not have an area association in its declaration, then it is only with the POINTER built-in function that the offset variable can be used as a locator to address a variable within an area. For more information, see the description of the POINTER built-in function in the section POINTER in the chapter Open PL/I Built-Ins.

An OFFSET variable may be assigned a value in the following ways: