PreviousNext

Nonencapsulated Unions

To define a nonencapsulated union, use the following syntax:

[switch_type(datatype)] union [tag]

{

case

...

[default_case]

}

If a tag is supplied, it can be used in a type_specifier of the form shown in Unions.

A parameter or a structure field that is a nonencapsulated union must have an attribute attached to it. This attribute has the following form:

switch_is(attr_var)

where attr_var is the name of the parameter or structure field that is the discriminator for the union.

If a nonencapsulated union is used as a structure field, the discriminator of the union must be a field of the same structure. If a nonencapsulated union is used as a parameter of an operation, the discriminator must be another parameter of the same operation.

The following example shows uses of a nonencapsulated union.

typedef

[switch_type(long)] union {

[case (1,3)] float a_float;

[case (2)] short b_short;

[default] ; /* An empty arm. Nothing is shipped. */

} n_e_union_t;

typedef

struct {

long a; /* The discriminant for the union later in this struct. */

[switch_is (a)] n_e_union_t b;

} a_struct;

/* Note switch can follow union in operation */

void op1 (

[in] handle_t h,

[in,switch_is (s)] n_e_union_t u,

[in] long s );