Connected: An Internet Encyclopedia
RFC 1832 - 3.19 Optional-data

Top: Connected: An Internet Encyclopedia
Up: Requests For Comments
Up: RFC 1832
Up: 3. XDR DATA TYPES
Prev: 3.18 Typedef
Next: 3.20 Areas for Future Enhancement

### 3.19 Optional-data

Optional-data is one kind of union that occurs so frequently that we give it a special syntax of its own for declaring it. It is declared as follows:

             type-name *identifier;

This is equivalent to the following union:

             union switch (bool opted) {
             case TRUE:
                type-name element;
             case FALSE:
                void;
             } identifier;

It is also equivalent to the following variable-length array declaration, since the boolean "opted" can be interpreted as the length of the array:

             type-name identifier<1>;

Optional-data is not so interesting in itself, but it is very useful for describing recursive data-structures such as linked-lists and trees. For example, the following defines a type "stringlist" that encodes lists of arbitrary length strings:

             struct *stringlist {
                string item<>;
                stringlist next;
             };

It could have been equivalently declared as the following union:

             union stringlist switch (bool opted) {
             case TRUE:
                struct {
                   string item<>;
                   stringlist next;
                } element;
             case FALSE:
                void;
             };

or as a variable-length array:

             struct stringlist<1> {
                string item<>;
                stringlist next;
             };

Both of these declarations obscure the intention of the stringlist type, so the optional-data declaration is preferred over both of them. The optional-data type also has a close correlation to how recursive data structures are represented in high-level languages such as Pascal or C by use of pointers. In fact, the syntax is the same as that of the C language for pointers.

Next: 3.20 Areas for Future Enhancement

Connected: An Internet Encyclopedia
RFC 1832 - 3.19 Optional-data