I am reading the RFC 4506 to understand the XDR data definition language.
It mentions that variable-length arrays are declared as follows.
type-name identifier<m>;
It also mentions that variable-length strings are declared as follows.
string object<m>;
Unfortunately, the only way it shows to have a variable length array of strings is a linked list, which seems very manual.
struct *stringlist {
string item<>;
stringlist next;
};
Is there a more simple or more correct way to declare a variable-length array of strings?
You can use the typedef
keyword.
typedef
does not declare any data either, but serves to define new identifiers for declaring data. The syntax is:typedef declaration;
The new type name is actually the variable name in the declaration part of the typedef. For example, the following defines a new type called "eggbox" using an existing type called "egg":
typedef egg eggbox[DOZEN];
We can define a variableLengthString
type with
typedef string variableLengthString<>;
and then declare a variableLengthString
array with
variableLengthString object<>;