union

The union keyword appears in functions that relate to discriminated unions.

MIDL supports two types of discriminated unions: encapsulated unions and nonencapsulated unions. The encapsulated union is compatible with previous implementations of RPC (NCA version 1). The nonencapsulated union eliminates some of the restrictions of the encapsulated union and provides a more visible discriminant than the encapsulated union.

The encapsulated union is identified by the switch keyword and the absence of other union-related keywords.

The nonencapsulated union, also known as a union, is identified by the presence of the switch_isMBJW8P and switch_typeF5.LML keywords, which identify the discriminant and its type. 

When you use in, out unions, be aware that changing the value of the union switch during the call can make the remote call behave differently from a local call. On return, the stubs copy the in, out parameter into memory that is already present on the client. When the remote procedure modifies the value of the union switch and consequently changes the data object s size, the stubs can overwrite valid memory with the out value. When the union switch changes the data object from a base type to a pointer type, the stubs can overwrite valid memory when they copy the pointer referent into the memory location indicated by the in value of a base type.

The shape of unions must be identical across platforms to ensure interconnectivity.

See Also

encapsulated_union, IDL, non-encapsulated_union, switch_is, switch_type