Project

General

Profile

IDL Constructed types

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

(93) constructed-type ::=

struct-type
| union-type
| enum-type

Structures

(94) struct-type ::=

"struct" struct-name "{" member-list "}"

(52) struct-name ::=

identifier

(95) member-list ::=

{ member ";" } member ";"

(96) member ::=

( type-spec
| member "," ) declarator

The identifier 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:

struct foo {
  long a;
  double x;
};

Discriminated unions

(97) union-type ::=

"union" union-name "switch" "(" switch-type-spec ")" "{" switch-body "}"

(53) union-name ::=

identifier

(98) switch-type-spec ::=

integer-type
| char-type
| boolean-type
| enum-type
| named-type

(99) switch-body ::=

{ case } case

(100) case ::=

case-label-list type-spec declarator ";"

(101) case-label-list ::=

{ case-label } case-label

(102) case-label ::=

( "case" 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 identifier 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

union foo switch(long) {
  case 0: long a;
  default: double x;
};

Enumerations

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

(103) enum-type ::=

"enum" identifier "{" enumerator-list "}"

(104) enumerator-list ::=

{ enumerator "," } enumerator

(105) enumerator ::=

identifier

A maximum of 232 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 identifier following the enum keyword defines a new legal type. Enumerated types may also be named using a typedef declaration.

Forward declarations

(106) forward-dcl ::=

( "struct"
| "union" ) identifier