Arrays within structs

A declaration of a struct member may either be a simple type-name member-name, or it may be an array of values of identical type.

Arrays are always indicated by square brackets:

STRUCT HAS_ARRAY
 {
 STRUCT elements[];
 }

In the example above, the HAS_ARRAY struct has one array member, elements. Each member of elements is of STRUCT type.

Array size

If you specify the array size, inside the square brackets, then the generated resource will contain no count of the number of elements. So this resource:

STRUCT FIXED_ARRAY
 {
 WORD elements[3];
 }

RESOURCE FIXED_ARRAY example1
 {
 elements={9,8,7};
 }

will generate the output

0x09 0x00 0x08 0x00 0x07 0x00

For variable length arrays, a count of the number of elements precedes the resource. The default for this is a word, but by prefixing the struct definition with LEN BYTE it will be a byte count. So the following resource:

STRUCT VAR_ARRAY
 {
 WORD elements [];
 }

RESOURCE VAR_ARRAY example2
 {
 elements={9,8,7};
 }

will generate the output

0x03 0x00 0x09 0x00 0x08 0x00 0x07 0x00 

whereas this resource:

STRUCT VAR_ARRAY2
 {
 LEN BYTE WORD elements[];
 }

RESOURCE VAR_ARRAY2 example3
 {
 elements={9,8,7};
 }

will generate this output

0x03 0x09 0x00 0x08 0x00 0x07 0x00

The compiler allows you to prefix LEN BYTE or LEN WORD even for fixed length arrays, but it has no effect. Fixed length arrays do not generate an element count.