[omniORB] unions.

David Scott djs@uk.research.att.com
Mon, 3 Apr 2000 11:34:18 +0100 (BST)


On Fri, 31 Mar 2000, Shawn Bisgrove wrote:

>   enum DomainType { DATE_VALUE, TEXT_VALUE };
>   union Domain switch (DomainType) {
>     case DATE_VALUE    DateRange d;
>     case TEXT_VALUE    TextRange t;
>   };
> 
>   struct myStruct {
>       string myDomainName;
>       boolean useableMyDomain;
>       Domain myDomain;
>   };
> 
>   Quick questions concerning C++ mapping.  For the
> above union should an additional _default member
> function be generated for the corresponding C++ class?
>
>From the CORBA 2.3 C++ language mapping, P1-34:

"... a union with an implicit default member provides a _default()
modifier function that sets the discriminant to a legal default value. A
union has an implicit default member if it does not have a default case
and not all permissible values of the discriminant are listed..."

In this example, there is no default case but all permissible values are
listed. Therefore a _default() member is not produced. 

If you change the enum to something like 
  enum DomainType { DATE_VALUE, TEXT_VALUE, OTHER_VALUE };
then a _default() member will be produced.

>  Just wondering?  If this is in a struct, is there a
> way to send this back uninitialized?
>
The default union constructor is not guaranteed to initialise either the
discriminator or any of the union members. You should make sure the member
is properly initialised before doing anything else with it.


-- 
  Dave Scott, Research Engineer, AT&T Research Cambridge UK