ONC+ Developer's Guide

RPCL Variable-Length Array Declarations

Variable-length array declarations have no explicit syntax in C. The XDR language does have a syntax, using angle brackets:

      type-ident variable-ident <value>
      type-ident variable-ident < > 

The maximum size is specified between the angle brackets. You can omit the size, indicating that the array can 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. An example is 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.