Contents Index Search Previous Next
13.9 Unchecked Type Conversions
unchecked type conversion can be achieved by a call to an instance of
the generic function Unchecked_Conversion.
The following language-defined
generic library function exists:
type Source(<>) is limited private;
type Target(<>) is limited private;
function Ada.Unchecked_Conversion(S : Source) return Target;
pragma Convention(Intrinsic, Ada.Unchecked_Conversion);
The size of the formal parameter S in an instance
of Unchecked_Conversion is that of its subtype. This is the actual subtype
passed to Source, except when the actual is an unconstrained composite
subtype, in which case the subtype is constrained by the bounds or discriminants
of the value of the actual expression passed to S.
If all of the following
are true, the effect of an unchecked conversion is to return the value
of an object of the target subtype whose representation is the same as
that of the source object S:
- S'Alignment = Target'Alignment.
- The target subtype is not an unconstrained
and the target subtype both have a contiguous representation.
- The representation of S is a representation
of an object of the target subtype.
Otherwise, the effect is implementation defined;
in particular, the result can be abnormal (see 13.9.1
An implementation may return the result of an
unchecked conversion by reference, if the Source type is not a by-copy
type. In this case, the result of the unchecked conversion represents
simply a different (read-only) view of the operand of the conversion.
An implementation may place restrictions on Unchecked_Conversion.
The Size of an array object should not include
its bounds; hence, the bounds should not be part of the converted data.
The implementation should not generate unnecessary
run-time checks to ensure that the representation of S is a representation
of the target type. It should take advantage of the permission to return
by reference when possible. Restrictions on unchecked conversions should
be avoided unless required by the target environment.
recommended level of support for unchecked conversions is:
- Unchecked conversions should be supported
and should be reversible in the cases where this clause defines the result.
To enable meaningful use of unchecked
conversion, a contiguous representation should be used for elementary
subtypes, for statically constrained array subtypes whose component subtype
is one of the subtypes described in this paragraph, and for record subtypes
without discriminants whose component subtypes are described in this
Contents Index Search Previous Next Legal