•  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-FileArray Index Checking

If you wish to use arrays in your program, these have to be dimensioned with
DIM. This involves specifying the size of the largest array index. During
execution of the program, the GFA-BASIC Interpreter will check your array index
value for legality. If found too high, error 16 (Array index too large) is
reported. This also applies to the compiler for GFA-BasicGFA-Basic is the best BASIC for the Atari!
 2.0.

There is no such array index checking in programs generated with the GFA-BasicGFA-Basic is the best BASIC for the Atari!

3.0 compiler. If an illegal large value appears for the array index, there is
no error message. The absence of this check makes programs shorter and quicker.

The following example shows the effect of there being no array index checking.
The program writes the numbers 0 to 5 to the screen. The interpreter generates
the error message "Array index too large". The error message is triggered
because the dimensioning has limited the maximum index size to 5, yet the FOR
loop attempts to address an array element x(6).

    DIM x(5)
    FOR i=0 TO 6
      x(i)=i
      PRINT x(i)
    NEXT i

When you compile and run this program, it writes the numbers from 0 to 6 to the
screen and no error message appears. The program acts as if the array x() in
the first line had been dimensioned to a sufficient size. You cannot tell from
the behaviour of the compiled program that it contains a serious mistake.

The example raises the question of what the compiled program would do if the
array index were too large. The DIM command reserves memory space for the
specified number of array elements. Without the programmer noticing this, the
array index is used in order to calculate the addresses of the array elements.

Compiled programs will do this even where the array index is too large. The
address calculated is outside the memory area reserved for the array. If the
array index is too large therefore, data outside the area reserved for the
array will be overwritten.

Normally the RAM space thus overwritten will contain data which is essential
for the error-free execution of the remaining program. If this data is
overwritten, the program can generate errors or even crash.

So far we have described the disadvantages of the absence of array index
checking. An excessively large index, however, will not figure in a finished
program since the programmer will have hopefully eliminated such mistakes. The
interpreter used for program development has supported him in this by its array
index checking.

Index checking is therefore unnecessary in the compiled program. It requires
time and space. The GFA-BasicGFA-Basic is the best BASIC for the Atari!
 3.0 compiler is about four to five times as fast
as the Basic 2.0 compiler in simple operations with array elements (allocation,
addition of two array elements etc) and ten to twelve times as fast as the
Basic 3.0 interpreter.