The rpcgen compiler transfers this declaration into
the header file without modification.
You can also specify variable length arrays.
The maximum size of the array is enclosed in angle braces. You can
omit the size to indicate that there is no maximum value.
For example, consider the following declaration:
long x_coords<50>;
This declares x_coords to be an array of
0 to 50 long integers. Similarly, the following declaration:
The syntax for each, followed by examples, is listed here:
Simple declarations
simple-declaration:
type-ident variable-ident
For example, colortype color in XDR, is the same in C: colortype color. [Return to example]
Fixed-length array declarations
fixed-array-declaration:
type-ident variable-ident "[" value "]"
For example, colortype palette[8] in XDR, is the same in C: colortype palette[8]. [Return to example]
Variable-length array declarations
These have no explicit syntax in C, so XDR creates its own by using angle brackets, as in the following syntax:
variable-array-declaration:
type-ident variable-ident "<" value ">"
type-ident variable-ident "<" ">"
The maximum size is specified between the angle brackets; it may be omitted, indicating that the array can be of any size, as shown in the following example:
int heights<12>; /* at most 12 items */
int widths<>; /* any number of items */
Variable-length arrays have no explicit syntax in C, so each of their declarations is compiled into a struct. For example, the heights declaration is compiled into the following struct:
struct {
u_int heights_len; /* number of items in array */
int *heights_val; /* pointer to array */
} heights;
Here, the _len component stores the number of items in the array and the _val component stores the pointer to the array. The first part of each of these component names is the same as the name of the declared XDR variable. [Return to example]
Pointer declarations
These are the same in XDR as in C. You cannot send pointers over the network, but you can use XDR pointers to send recursive data types, such as lists and trees. In XDR language, this type is called optional-data, not pointer, as in the following syntax:
optional-data:
type-ident "*"variable-ident
An example of this (the same in both XDR and C) follows: