OSF DCE Application Development Guide--Introduction and Style Guide

RPC Parameters
application must set the type field of this structure to either of the enumeration values
integers or ids. To return the union as an [out] or [in,out] parameter, the callee must
similarly be sure that the value of the type field is correctly set. To discover which data
type was marshalled, the recipient can check the value of the type field.
The following is an example of non-encapsulated union usage. The .idl declaration is as
follows:
typedef
[switch_type(long)] union {
[case (1,3)] float a_float;
[case (2)] short b_short;
[default]; /* An empty arm */
} n_e_union_t;
The C header declaration of the non-encapsulated union generated by the IDL compiler
is as follows:
typedef
union {
float a_float;
short b_short;
} n_e_union_t;
In this case, the discriminant must be separately declared in order for the union to be
marshalled. The IDL [switch_is] attribute identifies the discriminant for an instance of
the declared union type. Two examples of such .idl declarations follow:
/*
* A structure that includes the union declared above and a member
* that is used as the discriminant. This structure can be passed
* as an RPC parameter.
*/
typedef
struct {
long a;
[switch_is(a)] n_e_union_t b;
} a_struct;
/*
* An operation declaration that passes the declared union type along
* with a discriminant.
*/
void op1 (
[in] handle_t h,
[in, switch_is (s)] n_e_union_t u,
[in] long s
);
124246 Tandem Computers Incorporated 6 25