OSF DCE Application Development Guide--Introduction and Style Guide
RPC Parameters
avoid such complications by sticking to the more straightforward array usages discussed
here. However, if you find your application needs to use arrays in some more esoteric
way, you should refer to the AES/DC - RPC Volume, Chapter 4, which contains a
complete set of array and pointer usage rules.
6.3.6 Structures and Unions
There are no important policy issues relating to structures and unions as RPC parameters.
Pointers and arrays as members of structures and unions are sometimes treated
differently from separately declared types. By embedding pointers and arrays in
structures and unions, you can sometimes achieve behavior that cannot be obtained by
passing them as separate parameters.
Structures and unions can be used wherever they would be used in a non-RPC
application. IDL structures differ from C language structures in one important respect:
they may contain conformant arrays, which are not supported by C. A structure that
contains a conformant array is itself conformant; that is, the size of the structure may not
be determined until runtime. Applications need to do some extra work to determine the
size of, and allocate, conformant structures. When structures are used to create linked
lists and trees, the stubs do considerable work to insure that server allocated data is
reflected back to the client.
IDL union syntax is quite different from C syntax, since IDL unions must be
discriminated so that stubs can determine which of the contained data types to marshal.
As with conformant and varying arrays, which use a field attribute variable to determine
array size and bounds at runtime, IDL unions use a discriminator variable to determine
which data type is marshalled.
IDL unions may be encapsulated or non-encapsulated. In an encapsulated union, the IDL
compiler packages the union type and the discriminator in a structure. In a
nonencapsulated union, the IDL switch_is] attribute is used to identify a discriminator
variable. In this case, as in the case of array field attribute variables, the application must
declare the discriminator and the union together, either as members of a structure or as
parameters of an operation.
When a union is passed as a parameter, the value of the discriminator must either match
one of the constants declared in the switch construct, or the switch must contain a
default case. Otherwise, a stub marshalling error will occur.
Following are several examples of IDL union syntax. They are accompanied by the
resulting IDL generated C header file declarations, and show how applications must refer
to the union constructs declared in the IDL. The first example shows a set of
declarations for an encapsulated union. The union holds either of two structures, one
containing UUIDs, the other unsigned integers.
124246 Tandem Computers Incorporated 6− 23