Referencing DIMX Variables

Added September 2010

Compiler enhancement (edit 463): Functions and procedures may use ++EXTERN to reference DIMX variables, including those with AUTO_EXTEND. For example:

DIMX A(10),S,20

DIMX B(10),S,0,AUTO_EXTEND

CALL TEST()

PRINT A(10)

PRINT B(50)

END

 

PROCEDURE TEST()

    ++EXTERN A()

    ++EXTERN B()

    A(10) = "This is A(10)"

    B(50) = "This is B(50)"  ! should cause auto-expansion

ENDPROCEDURE

 

In the above example, the two arrays get initially allocated to 10 elements each before the call to the TEST() procedure. Within the procedure, we assign values to A(10) and B(50). In the latter case, the assignment causes both the B() array to be auto-extended (from 10 to 50+ elements), but also, since the elements of B() are themselves dynamic strings, memory for the B(50) element is created. On return, both values are printed, demonstrating that the manipulations and assignments to the arrays within the procedure are actually operating on the global arrays. (This technique provides a workaround to the restriction of not being able to pass a DIMX array as a parameter to a procedure or function.)

Note that you still must make sure to actually execute the DIMX statement before referencing an element in the array. (Often DIMX statements are placed out of the initial flow of control, in order to allow the dimensions to be calculated before the array is initialized. The need for that is considerably reduced by the AUTO_EXTEND (5.1.1190) feature, as well as ability to create an array of dynamically sized elements (5.1.1159). Any reference to an array whose DIMX has not yet been executed will result in an illegal subscript error.)