Please enable JavaScript to view this site.

ASQL Reference

Navigation: » No topics above this level «

Dynamic Variables Below MAP1

Scroll Prev Top Next More

Added February 2015

Note: This function was added to A-Shell in an experimental context. Please use with caution, test thoroughly, and report your experiences back to the A-Shell developers.

It is possible to allow dynamic variables (s,0 and x,0) below the MAP1 level. For example:

DEFSTRUCT ST_REC

    MAP2 SKU,S,10

    MAP2 DESCR,S,0      ! variable length!!

    MAP2 PRICE,F

ENDSTRUCT

 

This can be a useful technique for encapsulating data with variable-length components, but it creates an implicit linkage between the structure and the variable length elements that opens the door to various kinds of risks if not handled carefully. The size of the structure is fixed—the variable length field appears to have a fixed length of 16 bytes—but the contents of the variable length member are stored outside the structure, in the dynamic variable pool. The structure can be passed as a parameter to a function, and the variable length elements will remain intact, but at that point they should be treated as read-only. Both copies of the structure would link to the same variable-length text, but if that text is changed, only the current structure would remain properly linked to the updated text.

Writing the structure to a file would also make no sense; in that case, what would actually be written for the dynamic members would be their 16 byte descriptors, which would be useless outside the immediate context of the program.

History

2014 October, A-Shell 6.1.1391, compiler edit 712:  Added to A-Shell