Overview of Ada 2022
7.8 Aggregates of Unchecked_Unions using named notation
Given that it is generally
regarded as good practice to use named notation rather than positional
notation, it was somewhat bizarre that Unchecked_Unions only allowed
the latter.
Both are now allowed by
Aggregates
of Unchecked_Unions using named notation (AI12-0174)
(see RM
B.3.3).
For example:
type Data_Kind is (C_int, C_char);
type C_Variant (Format : Data_Kind := C_int) is record
case Format is
when C_int =>
int_Val : C.int;
when C_char =>
char_Val : C.char;
end case;
end record
with Unchecked_Union, Convention => C;
Int1 : C_Variant := (C_int, 12); -- Always OK
Int2 : C_Variant := (Format => C_int, int_Val => 12);
-- Was illegal, now OK
© 2021, 2022 Jeff Cousins