Variable-length array declarations have no explicit syntax in C. The XDR language does have a syntax, using angle brackets:
variable-array-declaration: type-ident variable-ident <value> type-ident variable-ident < >
The maximum size is specified between the angle brackets. The size may be omitted, indicating that the array may be of any size:
int heights<12>; /* at most 12 items */ int widths<>; /* any number of items */
Because variable-length arrays have no explicit syntax in C, these declarations are compiled into struct
declarations. For example, the heights declaration compiled into the following struct
:
struct { u_int heights_len; /* # of items in array */ int *heights_val; /* pointer to array */ } heights;
The number of items in the array is stored in the _len component and the pointer to the array is stored in the _val component. The first part of each component name is the same as the name of the declared XDR variable (heights).