Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
arrays [2019/04/07 22:24] – created neilsarrays [2019/06/27 07:42] neils
Line 1: Line 1:
 ====== Arrays ====== ====== Arrays ======
  
-Arrays must be defined using the ''DIM'' statement. As of the current version, maximum two-dimensional arrays are supported and both dimensions are limited to a length of 32767 elements. However, this is just a theoretical limit, in practice you'll run out of memory earlier. Arrays are zero-based (the first index is 0) and only integers may be used as indices.+Arrays must be defined using the ''DIM'' statement. As of the current version, maximum two-dimensional arrays are supported and both dimensions are limited to a length of 32767 elements. However, this is just a theoretical limit, in practice you'll run out of memory earlier. Arrays are zero-based (the first index is 0). Floats are not allowed as indices.
  
 The syntax to define array is the following (note the square brackets): The syntax to define array is the following (note the square brackets):
Line 23: Line 23:
   end   end
  
-Arrays are not initialized, which means that if you read the value of an array member without previously assigning a value to it, you will get unexpected results. For example:+**''DIM'' does not initialize the array**, which means that if you read the value of an array member without previously assigning a value to it, you will get unexpected results. For example:
  
   dim a[10]   dim a[10]
Line 29: Line 29:
   rem ** this will print an undefined number **   rem ** this will print an undefined number **
  
-Important: there is no runtime array bounds checking! The programmer has to make sure that the array subscript returns a number that is within the bounds of the array. Otherwise the result will be undefined.+**Important note**: there is no runtime array bounds checking! The programmer has to make sure that the array subscript returns a number that is within the bounds of the array. Otherwise the result will be undefined. 
 + 
 +===== Fast array lookup ===== 
 + 
 +If the variable and index are both byte types, the compiler can take advantage of the processor's indexed addressing mode resulting to much faster array load and store  operations. 
 + 
 +For example: 
 + 
 +  dim arr![255] 
 +  fastindex! = 42 
 +  slowindex = 42 
 +  rem -- fast lookup 
 +  item! = arr![fastindex!] 
 +  rem -- slow lookup 
 +  item! = arr![slowindex] 
 +   
 +~~DISCUSSION~~