Annotated Ada Reference ManualLegal Information
Table of Contents   Index   References   Search   Previous   Next 

 B.3.3 Pragma Unchecked_Union

1/2
{AI95-00216-01} {union (C)} [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

2/2
{AI95-00216-01} The form of a pragma Unchecked_Union is as follows:
3/2
  pragma Unchecked_Union (first_subtype_local_name);

Legality Rules

4/2
{AI95-00216-01} Unchecked_Union is a representation pragma, specifying the unchecked union aspect of representation.
5/2
{AI95-00216-01} The first_subtype_local_name of a pragma Unchecked_Union shall denote an unconstrained discriminated record subtype having a variant_part.
6/2
{AI95-00216-01} {unchecked union type} {unchecked union subtype} {unchecked union object} 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.
7/2
{AI95-00216-01} All component subtypes of an unchecked union type shall be C-compatible.
8/2
{AI95-00216-01} 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.
9/2
{AI95-00216-01} Any name that denotes a discriminant of an object of an unchecked union type shall occur within the declarative region of the type.
10/2
 {AI95-00216-01} A component declared in a variant_part of an unchecked union type shall not have a controlled, protected, or task part.
11/2
 {AI95-00216-01} The completion of an incomplete or private type declaration having a known_discriminant_part shall not be an unchecked union type.
12/2
 {AI95-00216-01} 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.
12.a/2
Ramification: This includes formal private types without a known_discriminant_part, formal derived types that do not inherit any discriminants (formal derived types do not have known_discriminant_parts), and formal derived types that are unchecked union types. 

Static Semantics

13/2
 {AI95-00216-01} An unchecked union type is eligible for convention C.
14/2
 {AI95-00216-01} All objects of an unchecked union type have the same size.
15/2
 {AI95-00216-01} Discriminants of objects of an unchecked union type are of size zero.
16/2
 {AI95-00216-01} Any check which would require reading a discriminant of an unchecked union object is suppressed (see 11.5). These checks include:
17/2
18/2
19/2
19.a/2
Discussion: If a suppressed check would have failed, execution is erroneous (see 11.5). An implementation is always allowed to make a suppressed check if it can somehow determine the discriminant value. 

Dynamic Semantics

20/2
 {AI95-00216-01} 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.{inferable discriminants}
21/2
 {AI95-00216-01} 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.
22/2
 {AI95-00216-01} Program_Error is raised in the following cases:{Program_Error (raised by failure of run-time check)}
23/2
24/2
25/2
26/2
27/2
28/2

Implementation Permissions

29/2
 {AI95-00216-01} An implementation may require that pragma Controlled be specified for the type of an access subcomponent of an unchecked union type.
NOTES
30/2
15  {AI95-00216-01} 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:
31/2
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);
32/2
X : T;
Y : Integer := X.F2; -- erroneous

Extensions to Ada 95

32.a/2
{AI95-00216-01} {extensions to Ada 95} Pragma Unchecked_Union is new. 

Table of Contents   Index   References   Search   Previous   Next 
Ada-Europe Sponsored by Ada-Europe