// Generated from idltype-constr.y - manual changes will be lost
ifdef::sidebartoc[]
include::_Sidebar.adoc[]
endif::[]


























IDL Constructed types
---------------------

`structs`, `unions` and `enums` are the constructed types. Their syntax is
presented in this section:

****
[horizontal]
(94) `*constructed-type      ::=*` ::
   <<grammar#dotgen-rule-struct-type,`struct-type`>> +
                              `|` <<grammar#dotgen-rule-union-type,`union-type`>> +
                              `|` <<grammar#dotgen-rule-enum-type,`enum-type`>>
****






=== Structures

****
[horizontal]
(95) `*struct-type           ::=*` ::
   `"struct"` <<grammar#dotgen-rule-struct-name,`struct-name`>> `"{"` <<grammar#dotgen-rule-member-list,`member-list`>> `"}"`
(53) `*struct-name           ::=*` ::
   <<grammar#dotgen-rule-identifier,`identifier`>>
(96) `*member-list           ::=*` ::
   `{` <<grammar#dotgen-rule-member,`member`>> `";"` `}` <<grammar#dotgen-rule-member,`member`>> `";"`
(97) `*member                ::=*` ::
   `(` <<grammar#dotgen-rule-type-spec,`type-spec`>> +
                              `|` <<grammar#dotgen-rule-member,`member`>> `","` `)` <<grammar#dotgen-rule-declarator,`declarator`>>
****

The `identiﬁer` in `struct-type` defines a new legal type. Structure types
may also be named using a typedef declaration.

Name scoping rules require that the member declarators in a particular
structure be unique.

==== Example

Here is a small structure definition with one integer and one double
precision value:

[source,C]
----
struct foo {
  long a;
  double x;
};
----
































































=== Discriminated unions

****
[horizontal]
(98) `*union-type            ::=*` ::
   `"union"` <<grammar#dotgen-rule-union-name,`union-name`>> `"switch"` `"("` <<grammar#dotgen-rule-switch-type-spec,`switch-type-spec`>> `")"` `"{"` <<grammar#dotgen-rule-switch-body,`switch-body`>> `"}"`
(54) `*union-name            ::=*` ::
   <<grammar#dotgen-rule-identifier,`identifier`>>
(99) `*switch-type-spec      ::=*` ::
   <<grammar#dotgen-rule-integer-type,`integer-type`>> +
                              `|` <<grammar#dotgen-rule-char-type,`char-type`>> +
                              `|` <<grammar#dotgen-rule-boolean-type,`boolean-type`>> +
                              `|` <<grammar#dotgen-rule-enum-type,`enum-type`>> +
                              `|` <<grammar#dotgen-rule-named-type,`named-type`>>
(100) `*switch-body           ::=*` ::
   `{` <<grammar#dotgen-rule-case,`case`>> `}` <<grammar#dotgen-rule-case,`case`>>
(101) `*case                  ::=*` ::
   <<grammar#dotgen-rule-case-label-list,`case-label-list`>> <<grammar#dotgen-rule-type-spec,`type-spec`>> <<grammar#dotgen-rule-declarator,`declarator`>> `";"`
(102) `*case-label-list       ::=*` ::
   `{` <<grammar#dotgen-rule-case-label,`case-label`>> `}` <<grammar#dotgen-rule-case-label,`case-label`>>
(103) `*case-label            ::=*` ::
   `(` `"case"` <<grammar#dotgen-rule-const-expr,`const-expr`>> +
                              `|` `"default"` `)` `":"`
****

Unions are a cross between the C union and switch statements. Unions must be
discriminated; that is, the union header must specify a typed tag field that
determines which union member to use for the current instance of a call. The
`identiﬁer` following the union keyword defines a new legal type. Union
types may also be named using a typedef declaration. The `const_exp` in a
`case_label` must be consistent with the `switch_type_spec`. A default case
can appear at most once. The `named-type` in the `switch-type-spec`
production must be a previously defined integer, char, boolean or enum type.

Case labels must match or be automatically castable to the defined type of
the discriminator. Name scoping rules require that the element declarators
in a particular union be unique. It is not required that all possible values
of the union discriminator be listed in the `switch-body`.

==== Example

[source,C]
----
union foo switch(long) {
  case 0: long a;
  default: double x;
};
----








































































































=== Enumerations

Enumerated types consist of ordered lists of identifiers. The syntax is:

****
[horizontal]
(104) `*enum-type             ::=*` ::
   `"enum"` <<grammar#dotgen-rule-identifier,`identifier`>> `"{"` <<grammar#dotgen-rule-enumerator-list,`enumerator-list`>> `"}"`
(105) `*enumerator-list       ::=*` ::
   `{` <<grammar#dotgen-rule-enumerator,`enumerator`>> `","` `}` <<grammar#dotgen-rule-enumerator,`enumerator`>>
(106) `*enumerator            ::=*` ::
   <<grammar#dotgen-rule-identifier,`identifier`>>
****

A maximum of 2^32^ identifiers may be specified in an enumeration. The order
in which the identifiers are named in the specification of an enumeration
defines the relative order of the identifiers. The
`identiﬁer` following the enum keyword defines a new legal type. Enumerated
types may also be named using a typedef declaration.












































=== Forward declarations

****
[horizontal]
(107) `*forward-dcl           ::=*` ::
   `(` `"struct"` +
                              `|` `"union"` `)` <<grammar#dotgen-rule-identifier,`identifier`>>
****













// eof
