•  Back 
  •  Main 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The GFA-Basic Compendium
Author      : GFA Systemtechnik GmbH
Version     : GFABasic.HYP v2.98 (12/31/2023)
Subject     : Documentation/Programming
Nodes       : 899
Index Size  : 28056
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : 
@default    : Document not found
@help       : Help
@options    : +g -i -s +z
@width      : 75
@hostname   : STRNGSRV
@hostname   : CAB     
@hostname   : HIGHWIRE
@hostname   : THING   
View Ref-FileDIM x(d1,[d2,...]) [,y(d1,[d2,...])]
DIM?(x())

x, y: variable name (arbitrary variable type)
d1, d2: iexp

With the instruction DIM numerical and character string arrays can be declared.
The structure of such an array was explained in the introduction of this
section.

An array with one dimension is only limited by memory. DIM b|(131072) would
use 128kb of ram.

Multi-dimensional arrays have two or more dimensions and follow different
rules. The possible number of the dimensions of the array is only limited by:

A) The dimensions must all be smaller than 65535
B) The product of the field elements must be smaller than 65535
C) The limit on the number of dimensions is 7

So DIM a%(100,10,10) is permitted, as all the dimensions and the product
of the field elements (100*10*10=10000) are both less than 65535.

In an array, only variables of the same type may exist. The type of array takes
precedence over the type of number put into it.

The function DIM?() determines the total number of elements in an array.

Example:

    DIM x(10)
    x(4)=3
    PRINT x(LEN("test"))
    PRINT DIM?(x())
    '
    DIM y%(2,3)
    PRINT DIM?(y%())

--> Two arrays are declared. The output on the screen consists of the
    numbers 3, 11, and 12.

Memo: DIM should not be used within a FUNCTION. It seems to clobber any
      LOCAL variables defined within the FUNCTION. See 'The local=FN bug'
      notes from the GFA Basic FAQ by Bo Leuf.

      DIM seems to crash the compiler if one attempts 8 dimensions:
      DIM a&(1,2,3,4,5,6,7,8) <- causes the compiler to crash
      DIM a&(1,1,1,1,1,1,1,1) <- runs ok in the editor!

      The limit of 65535 elements for multi-dimensional arrays doesn't work
      correctly:
      DIM x|(800,800)   !no error issued
      DIM x|(800,800,1) !error is issued

      How DIM?() works based on OPTION BASE:
      OPTION BASE 0
      DIM y%(2,3): -> 0-2,0-3 -> 3*4=12
      OPTION BASE 1
      DIM y%(2,3): -> 1-2,1-3 -> 2*3=6