Please enable JavaScript to view this site.

A-Shell Consolidated Reference

A dynamic array of DEFSTRUCT may be defined and allocated as follows:

DEFSTRUCT ST_MOVIE_PROD

    MAP2 TITLE$,S,30

    MAP2 PRODUCERS(9),S,30

ENDSTRUCT

 

...

 

DIMX DMVPR(N),ST_MOVIE_PROD  ! dynamic array of N structures

DIMX FX(N),X,300             ! dynamic array of N ordinary X,300 variables

MAP1 FMVPR(10),ST_MOVIE_PROD ! fixed array of 10 structures

...

DMVPR(1) = FX(1)             ! assign one X,300 var to another

 

Note: initial values specified in the MAP Statements within the structure definition are ignored by DIMX. All elements/fields are initialized to null. See the A-Shell forum discussion "MAP initializers in DEFSTRUCT."

As shown above, the declaration of the dynamic array of structures is syntactically consistent with both static arrays of structures and dynamic arrays of ordinary types (with the structure name replacing the type,size pair). The assignment statement following the declarations also illustrates that the DMVPR() array of structures and the FX() array of simple X,300 variables are, at the top level, compatible, since at the top level, an instance of the ST_MOVIE_PROD structure is equivalent to an instance of an X,300 variable. The FX() array though, provides no direct means of referencing individual fields within each unformatted element, so we'll set that aside for a moment and concentrate on the differences between the fixed and dynamic arrays DMVPR() and FMVPR().

Although the fixed and dynamic arrays are logically similar, the normal organization of fixed arrays of structures, in which each member can be accessed as if it were an independent array, i.e. FMVPR.TITLE$(J), is not efficient for dynamic (moveable) arrays. Consequently, both the structure and the syntax of accessing the individual element members of dynamic arrays is reversed, so that you append the "dot member" name after the structure element subscript, e.g.:

PRINT DMVPR(J).TITLE$    ! member of dynamic array of structures

PRINT FMVPR.TITLE$(J)    ! member of fixed array of structures

 

C programmers will recognize the correspondence to the way elements within arrays of structures are accessed in that language.

When the member is itself an array, as in the case of PRODUCERS(), you end up with two sets of parentheses:

PRINT DMVPR(J).PRODUCERS(K)    ! dynamic array

PRINT FMVPR.PRODUCTS(J,K)      ! fixed array

 

As with other DIMX arrays, the AUTO_EXTEND, PUBLIC, and PRIVATE modifiers are all available. See Dynamic Arrays (DIMX) and MAP Statement Extensions.

See Also

Passing DIMX Arrays (as parameters)

History

2011 October A-Shell 5.1.1235: DIMX structures implemented.