2.2.7 References

A reference value is either NIL or the address of a variable, called the referent.

A reference type is either traced or untraced. When all traced references to a piece of allocated storage are gone, the implementation reclaims the storage. Two reference types are of the same reference class if they are both traced or both untraced. A general type is traced if it is a traced reference type, a record type any of whose field types is traced, an array type whose element type is traced, or a packed type whose underlying unpacked type is traced.

A declaration for a traced reference type has the form:

    TYPE T = REF Type
where Type is any type. The values of T are traced references to variables of type Type, which is called the referent type of T.

A declaration for an untraced reference type has the form:

    TYPE T = UNTRACED REF Type
where Type is any untraced type. (This restriction is lifted in unsafe modules.) The values of T are the untraced references to variables of type Type.

In both the traced and untraced cases, the keyword REF can optionally be preceded by ``BRANDED b'' where b is a text constant called the brand. Brands distinguish types that would otherwise be the same; they have no other semantic effect. All brands in a program must be distinct. If BRANDED is present and b is absent, the implementation automatically supplies a unique value for b. Explicit brands are useful for persistent data storage.

The following reference types are predeclared:

REFANY Contains all traced references
ADDRESS Contains all untraced references
NULL Contains only NIL
The TYPECASE statement can be used to test the referent type of a REFANY or object, but there is no such test for an ADDRESS.

Examples of reference types:

    TYPE TextLine = REF ARRAY OF CHAR;

    ControllerHandle = UNTRACED REF RECORD
      status: BITS 8 FOR [0..255];
      filler: BITS 12 FOR [0..0];
      pc: BITS 12 FOR [0..4095]
    END;

    T = BRANDED "ANSI-M3-040776" REF INTEGER;

    Apple  = BRANDED REF INTEGER;
    Orange = BRANDED REF INTEGER;

m3-support@elego.de