+4.2.2 Variants (Discriminated Unions)
+
+A CTF variant is a selection between different types. A CTF variant must always
+be defined within the scope of a structure or within fields contained within a
+structure (defined recursively). A "tag" enumeration field must appear in either
+the same lexical scope or an uppermost scope, prior to the variant field (in
+field declaration order). The type selection is indicated by the mapping from
+the enumeration value to the string used as variant type selector. The field to
+use as tag is specified by the "tag_field", specified between "< >" after the
+"variant" keyword for unnamed variants, and after "variant name" for named
+variants.
+
+The alignment of the variant is the alignment of the type as selected by the tag
+value for the specific instance of the variant. The alignment of the type
+containing the variant is independent of the variant alignment. The size of the
+variant is the size as selected by the tag value for the specific instance of
+the variant.
+
+A named variant declaration followed by its definition within a structure
+declaration:
+
+variant name {
+ field_type sel1;
+ field_type sel2;
+ field_type sel3;
+ ...
+};
+
+struct {
+ enum <integer_type or size> { sel1, sel2, sel3, ... } tag_field;
+ ...
+ variant name <tag_field> v;
+}
+
+An unnamed variant definition within a structure is expressed by the following
+metadata:
+
+struct {
+ enum <integer_type or size> { sel1, sel2, sel3, ... } tag_field;
+ ...
+ variant <tag_field> {
+ field_type sel1;
+ field_type sel2;
+ field_type sel3;
+ ...
+ } v;
+}
+
+Example of a named variant within a sequence that refers to a single tag field:
+
+variant example {
+ uint32_t a;
+ uint64_t b;
+ short c;
+};
+
+struct {
+ enum <uint2_t> { a, b, c } choice;
+ variant example <choice> v[unsigned int];
+}
+
+Example of an unnamed variant:
+
+struct {
+ enum <uint2_t> { a, b, c, d } choice;
+ /* Unrelated fields can be added between the variant and its tag */
+ int32_t somevalue;
+ variant <choice> {
+ uint32_t a;
+ uint64_t b;
+ short c;
+ struct {
+ unsigned int field1;
+ uint64_t field2;
+ } d;
+ } s;
+}
+
+Example of an unnamed variant within an array:
+
+struct {
+ enum <uint2_t> { a, b, c } choice;
+ variant <choice> {
+ uint32_t a;
+ uint64_t b;
+ short c;
+ } v[10];
+}
+
+Example of a variant type definition within a structure, where the defined type
+is then declared within an array of structures. This variant refers to a tag
+located in an upper lexical scope. This example clearly shows that a variant
+type definition referring to the tag "x" uses the closest preceding field from
+the lexical scope of the type definition.
+
+struct {
+ enum <uint2_t> { a, b, c, d } x;
+
+ typedef variant <x> { /*
+ * "x" refers to the preceding "x" enumeration in the
+ * lexical scope of the type definition.
+ */
+ uint32_t a;
+ uint64_t b;
+ short c;
+ } example_variant;
+
+ struct {
+ enum <int> { x, y, z } x; /* This enumeration is not used by "v". */
+ example_variant v; /*
+ * "v" uses the "enum <uint2_t> { a, b, c, d }"
+ * tag.
+ */
+ } a[10];
+}
+
+4.2.3 Arrays