Pointers to arrays with dual indexes

Indexed pointers with dual indexes require an "OF limit" clause on both indexes.  While simple arrays (arrays with one index) store data sequentially, dual indexes interleave each row of data.  The OF clause is used by the compiler to calculate the size of each row and column.  limit is the upper bound of the index (zero-based):

DIM DataPtr AS INTEGER PTR

DIM z%(0 TO 8, 0 TO 3)

DataPtr = VARPTR(z%(0, 0))

FOR y = 0 TO 3

  FOR x = 0 TO 8

    Value% = @DataPtr[x OF 8, y OF 3]

  NEXT x

NEXT y

The following example uses a lower bound other than zero:

DIM DataPtr AS INTEGER PTR

DIM z%(1990 TO 1998, -1 TO 3)

DataPtr = VARPTR(z%(1990, -1))

FOR y = 0 TO 4

  FOR x = 0 TO 8

    Value% = @DataPtr[x OF 8, y OF 4]

  NEXT x

NEXT y

If you subtract the lower bound from itself and the upper bound (to get a lower bound of zero), you get 8 for the upper bound, which is then used for limit after the OF keyword.

 

See Also

Pointers (@)

Pointers to ASCIIZ and fixed-length strings

Pointers to arrays