- 论坛徽章:
- 84
|
更详细的介绍: http://neo.dmcs.pl/rso/du/onc-rpc3.html
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:
listitem *next;
|
|