Previous Table of Contents Next


18.2.6 Mapping for Union Types


   OMG IDL defines unions to be encapsulated discriminated unions: the discriminator itself must be encapsulated within the union.

   In addition, the OMG IDL union discriminants must be constant expressions. The discriminator tag must be a previously defined long, short, unsigned long, unsigned short, char, boolean, or enum constant. The default case can appear at most once in the definition of a discriminated union, and case labels must match or be automatically castable to the defined type of the discriminator.

   The following definition for a discriminated union in OMG IDL

   // OMG IDLenum UNION_DISCRIMINATOR

   {dChar=0,dShort,dLong,dFloat,dDouble

   };

   union UNION_OF_CHAR_AND_ARITHMETICswitch(UNION_DISCRIMINATOR){

   case dChar: char c;case dShort: short s;case dLong: long l;case dFloat: float f;case dDouble: double d;default: octet v[;8];

   };

   is mapped into encapsulated unions in Microsoft IDL as follows:

   // Microsoft IDL

   typedef enum [v1 enum]{dchar=0,dShort,dLong,dFloat,dDouble} UNION_DISCRIMINATOR;

   typedef union switch (UNION_DISCRIMINATOR DCE_d){case dChar: char c;case dShort: short s;case dLong: long l;case dFloat: float f;case dDouble: double d;default: byte v[8];}UNION_OF_CHAR_AND_ARITH