Next: , Previous: , Up: Structs   [Contents][Index]


17.5.12 Unions

Union types are defined much like struct types, using a very similar syntax:

union
{
  [... elements ...]
}

Like in structs, the main kind of elements are fields. However, unlike in structs, the fields in an union type denote alternatives. At any given time, only one alternative is selected, and therefore union values have only one field.

Which of the several alternatives is selected is determined by the data integrity defined by means of constraint expressions and other means. Alternatives are considered in turn, in written order, and the first alternative that can be used without triggering a constraint violation exception is selected.