Next: , Previous: Pragma Title, Up: Implementation Defined Pragmas


Pragma Unchecked_Union

Syntax:

     pragma Unchecked_Union (first_subtype_local_NAME);

This pragma is used to declare that the specified type should be represented in a manner equivalent to a C union type, and is intended only for use in interfacing with C code that uses union types. In Ada terms, the named type must obey the following rules:

In addition, given a type that meets the above requirements, the following restrictions apply to its use throughout the program:

Equality and inequality operations on unchecked_unions are not available, since there is no discriminant to compare and the compiler does not even know how many bits to compare. It is implementation dependent whether this is detected at compile time as an illegality or whether it is undetected and considered to be an erroneous construct. In GNAT, a direct comparison is illegal, but GNAT does not attempt to catch the composite case (where two composites are compared that contain an unchecked union component), so such comparisons are simply considered erroneous.

The layout of the resulting type corresponds exactly to a C union, where each branch of the union corresponds to a single variant in the Ada record. The semantics of the Ada program is not changed in any way by the pragma, i.e. provided the above restrictions are followed, and no erroneous incorrect references to fields or erroneous comparisons occur, the semantics is exactly as described by the Ada reference manual. Pragma Suppress (Discriminant_Check) applies implicitly to the type and the default convention is C.