Pointer Expression

A pointer expression is an expression that returns a value that is a pointer, which can be used to reference a character position in an array row.

<pointer expression>

──┬─<simple pointer expression>──────┬─────────────────────────────────┤
  ├─<conditional pointer expression>─┤
  └─<try pointer expression>─────────┘

<simple pointer expression>

──┬─<pointer primary>─┬─────────────────────────────────────┬──────────┤
  │                   └─<skip>──────────────────────────────┤
  ├─<pointer assignment>────────────────────────────────────┤
  ├──────────────────────────────┬─┬─<character array part>─┤
  ├─<connection block qualifier>─┤ └─<word array part>──────┘
  └─<structure block qualifier>──┘

<pointer primary>

──┬─<pointer identifier>───────────┬───────────────────────────────────┤
  ├─ ( ──<pointer expression>── ) ─┤
  ├─<pointer case expression>──────┤
  └─<pointer function designator>──┘

<pointer case expression>

                   ┌◄───────── , ─────────┐
──<case head>── ( ─┴─<pointer expression>─┴─ ) ────────────────────────┤

<skip>

──┬─ + ─┬─<arithmetic primary>─────────────────────────────────────────┤
  └─ - ─┘

<character array part>

──┬─<character array row>───────────────────────────┬──────────────────┤
  │                             ┌◄───── , ────┐     │
  └─<character array name>── [ ─┴─<subscript>─┴─ ] ─┘

<word array part>

──┬─<word array row>───────────────────────────┬──────────────────┤
  │                        ┌◄───── , ────┐     │
  └─<word array name>── [ ─┴─<subscript>─┴─ ] ─┘

<word array name>

An array name whose identifier is declared with a non-character type.

<character array row>

An array row whose identifier is declared with a character type.

<word array row>

An array row whose identifier is declared with a noncharacter type.

<character array name>

An array name whose identifier is declared with a character type.

<conditional pointer expression>

──<if clause>──<pointer expression>── ELSE ──<pointer expression>──────┤

<try pointer expression>

── TRY ──<try pointer normal form>─────────────────────────────────────┤

<try pointer normal form>

                       ┌◄─────────────────────────────┐
──<pointer expression>─┴─ ELSE ──<pointer expression>─┴────────────────┤

An explanation of <try pointer expression> is given in TRY Expression.

A pointer must be initialized before it can be used; otherwise, a run-time error occurs. A pointer can be initialized in the following ways:

  • By the use of a pointer assignment

  • By the appearance of an update pointer in any of the following:

    • A REPLACE statement

    • A SCAN statement

    • A string relation in a Boolean expression

    • The DINTEGER function

    • The DOUBLE function

    • The INTEGER function

When a one-dimensional array designator is used as a pointer expression, it references the beginning of the array, no matter what its lower bounds are.

The use of a <word array part> results in a word pointer that is not acceptable when a character pointer is required.

The evaluation of a conditional pointer expression is described in Conditional Expressions.

A one-dimensional array designator or a fully subscripted variable can be interpreted as a pointer primary whenever context determines that no conflict exists with other valid constructs (for example, when a pointer expression is required). This syntax can be used for such constructs as the following, where A and B are one-dimensional arrays:

REPLACE A BY B FOR 10 WORDS

The evaluation of a pointer case expression is described in Case Expression.

If the skip construct is used, the value of the arithmetic primary determines the adjustment to the value of the pointer primary. If N is the value of the arithmetic primary, the pointer is adjusted as follows:

  • If N is less than or equal to 0, the pointer is not adjusted.

  • If N is greater than 0, then the pointer is adjusted N characters to the right when the skip construct specifies "+", or N characters to the left if it specifies "–".

    Skipping to the right is defined as incrementing the value of the character index.

    Skipping to the left is defined as decrementing this value.

If the adjustment to the value of the pointer primary is given by the value of an arithmetic expression, note that the arithmetic expression must be enclosed in parentheses. For example, the following expression is invalid and generates a compile-time error:

PTR + X*Y

The expression is written correctly as follows:

PTR + (X*Y)

The use of a pointer expression to skip up and down an array for more than a few words is expensive. Each word of the array is accessed in order to ensure that no memory-protected words are encountered. For pointer moves of more than a few words, it is faster to reindex the array and use the POINTER function for word arrays, or to reindex the array for character arrays.

Examples of Pointer Expressions

PTR

PTS+15

PTR := POINTER(A)

(PTEMP + (X*Y))

HEXARAY

HEXARAY[N]

CASE VAL OF (PTR,PTS,PTEMP,PSORCE)

POINTER(INFO,8)

IF BOOL THEN P1 ELSE POINTER(A)