![]() |
In addition to the basic types, IDL also supports three constructed types:
- Structure (struct).
- Union (union).
- Enumeration (enum).
The structure and enumeration types are specified in IDL just as they are in C and C++, with the following restrictions:
- Recursive type specifications are allowed only through the use of the sequence template type.
- Structures and enumerations in IDL must be tagged. For example, struct { int a; ... } is an inappropiate type specification (because the tag is missing). The tag introduces a new type name.
- Structure and enumeration type definitions need not be part of a typedef statement; furthermore, if they are part of a typedef statement, the tag of the struct must differ from the type name being defined by the typedef. For example, the following are valid IDL struct and enum definitions:
struct myStruct { long x; double y; }; /* defines type name myStruct */ enum colors { red, white, blue }; /* defines type name colors */The following IDL definitions are not valid:
typedef struct myStruct { /* NOT VALID */ long x; /* Tag myStruct is the same */ double y; /* as the type name below; */ } myStruct; /* myStruct has been redefined */ typedef enum colors { red, white, blue } colors; /* NOT VALID */The IDL union type is a cross between the C union and switch statements. This type is specified in IDL just as it is in C and C++, with the restriction that discriminated unions in IDL must be tagged. The syntax of a union type declaration is as follows:
union identifier switch (switch-type) { case+ }
- The identifier following the union keyword defines a new legal type. (Union types can also be named using a typedef declaration.)
- The switch-type specifies an integral, character, boolean, or enumeration type, or the name of a previously defined integral, boolean, character or enumeration type.
- Each case of the union is specified with the following syntax:
case-label+ type-spec declarator;Where
- Each caselabel has one of the following forms:
case const-expr:default: The const-expr is a constant expression that must match or be automatically castable to the switch-type. A default case can appear no more than once.
- type-spec is any valid type specification.
- declarator is an identifier or an array declarator (such as, foo[3][5]).
Note: A deviation from CORBA specifications exists; there is no support of longlong discriminators in unions.