B.3.3 Pragma Unchecked_Union
A pragma Unchecked_Union specifies
an interface correspondence between a given discriminated type and some
C union. The pragma specifies that the associated type shall be given
a representation that leaves no space for its discriminant(s).
Syntax
The form of a pragma
Unchecked_Union is as follows:
pragma Unchecked_Union
(
first_subtype_local_name);
Legality Rules
Unchecked_Union is a representation pragma, specifying
the unchecked union aspect of representation.
A
type to which a pragma Unchecked_Union applies is called an
unchecked
union type. A subtype of an unchecked union type is defined to be
an
unchecked union subtype. An object of an unchecked union type
is defined to be an
unchecked union object.
All component subtypes of an unchecked union type
shall be C-compatible.
If a component subtype of an unchecked union type
is subject to a per-object constraint, then the component subtype shall
be an unchecked union subtype.
Any name that denotes a discriminant of an object
of an unchecked union type shall occur within the declarative region
of the type.
A component declared in a
variant_part
of an unchecked union type shall not have a controlled, protected, or
task part.
The completion of an incomplete or private type declaration
having a
known_discriminant_part
shall not be an unchecked union type.
An unchecked union subtype shall only be passed as
a generic actual parameter if the corresponding formal type has no known
discriminants or is an unchecked union type.
Static Semantics
An unchecked union type is eligible for convention
C.
All objects of an unchecked union type have the same
size.
Discriminants of objects of an unchecked union type
are of size zero.
Any check which would
require reading a discriminant of an unchecked union object is suppressed
(see
11.5). These checks include:
The check performed when addressing a variant component
(i.e., a component that was declared in a variant part) of an unchecked
union object that the object has this component (see
4.1.3).
Any checks associated with a type or subtype conversion
of a value of an unchecked union type (see
4.6).
This includes, for example, the check associated with the implicit subtype
conversion of an assignment statement.
The subtype membership check associated with the
evaluation of a qualified expression (see
4.7)
or an uninitialized allocator (see
4.8).
Dynamic Semantics
A view of an unchecked union object (including a
type conversion or function call) has
inferable discriminants
if it has a constrained nominal subtype, unless the object is a component
of an enclosing unchecked union object that is subject to a per-object
constraint and the enclosing object lacks inferable discriminants.
An expression of an unchecked union type has inferable
discriminants if it is either a name of an object with inferable discriminants
or a qualified expression whose
subtype_mark
denotes a constrained subtype.
Program_Error is raised
in the following cases:
Evaluation of the predefined equality operator
for an unchecked union type if either of the operands lacks inferable
discriminants.
Evaluation of the predefined equality operator
for a type which has a subcomponent of an unchecked union type whose
nominal subtype is unconstrained.
Evaluation of a membership test if the
subtype_mark
denotes a constrained unchecked union subtype and the expression lacks
inferable discriminants.
Conversion from a derived unchecked union type
to an unconstrained non-unchecked-union type if the operand of the conversion
lacks inferable discriminants.
Execution of the default implementation of the
Write or Read attribute of an unchecked union type.
Execution of the default implementation of the
Output or Input attribute of an unchecked union type if the type lacks
default discriminant values.
Implementation Permissions
An implementation may require that
pragma
Controlled be specified for the type of an access subcomponent of an
unchecked union type.
13 The use
of an unchecked union to obtain the effect of an unchecked conversion
results in erroneous execution (see
11.5).
Execution of the following example is erroneous even if Float'Size =
Integer'Size:
type T (Flag : Boolean := False) is
record
case Flag is
when False =>
F1 : Float := 0.0;
when True =>
F2 : Integer := 0;
end case;
end record;
pragma Unchecked_Union (T);
X : T;
Y : Integer := X.F2; -- erroneous