Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - [] array index delimiters http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 []                  Array index delimiters
------------------------------------------------------------------------------
 Syntax
   aVar[ nIndex ]

 Arguments
   aVar is an array variable identifier.

   nIndex is a numeric expression used as a subscript to address an
   individual array element.

 Description
   The [] operator is used to either declare or refer to an array.
   An array is a sequence of declared data types of a given length. Each
   array can only hold elements of a single data type.

   When declaring an array in a vardef block, the nIndex argument specifies
   the total number of elements, that is the size of the array. This
   value defines how many elements of the respective data type may be
   stored in the array. The total storage space of the array may not
   exceed 64 Kbytes (65535 bytes). To determine how much space an array
   occupies, multiply the array size by the memory size of a single
   element.

   Force arrays are zero-based, meaning that the first element of any array
   is indexed as element 0, and the subscript of the last one is (n - 1),
   where n is the array size specified when declaring the array.

   Exceeding the highest array index causes a run-time error, provided that
   array range checking code was generated by the compiler. Specifying
   the size of array parameters is not mandatory, but omitting the size
   disables array range checking for that array.

   An array without a subscript specifier always refers to element 0
   both for values (array elements) and addresses (whole arrays).

   Public and static arrays can be initialized at the place of declaration
   with constant values, e. g.:

   vardef
      char(9) aWeekDays[7] := "Sunday",    "Monday",   "Tuesday", ;
                              "Wednesday", "Thursday", "Friday", ;
                              "Saturday"
   enddef

   The number of elements in the comma-separated list of initializers must
   not exceed the number of declared array elements.

 Example
   #define EXAMPLE_OPERATOR
   #include example.hdr

   proc PassElement static
   para value uint uElement
   ? uElement
   endproc
   
   proc PassArray static      // array size checking is disabled
   param uint aNums[]         // by omitting array size specification
   vardef
      uint n
   enddef
   for n := 0 to 1
      ? aNums[ n ]            // prints 1 and 2 for exisiting array elements
   next
   for n := 2 to 3
      ? aNums[ n ]            // error: prints accidental values for
   next                       // non-existing array elements
   endproc
   
   vardef
      uint aTest[ 2 ] := 1, 2 // initialized public array with two elements
   enddef
   
   proc Test_946
   ? aTest[ 0 ]
   PassElement( aTest[ 0 ] )
   ?
   PassElement( aTest[] )     // the value of aTest[ 0 ] is passed
   ?
   PassArray( aTest[ 0 ] )
   ?
   PassArray( aTest[] )       // the address of aTest[ 0 ] is passed
   ?
   ? aTest[ 0 ]
   aTest[] := 99              // aTest[] refers to aTest[ 0 ]
   ? aTest[]
   ? aTest[ 0 ]
   ? aTest[] == aTest[ 0 ]    // prints .t.
   endproc

   proc main
   Test_946()
   endproc

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson