Skip to main content

13.6 Change of Representation


This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue


[ A type_conversion (see 4.6) can be used to convert between two different representations of the same array or record. To convert an array from one representation to another, two array types with matching component subtypes and convertible index types are required. If one type has Pack specified and the other does not, then explicit conversion can be used to pack or unpack an array.


To convert an untagged record from one representation to another, two record types with a common ancestor type are required . Distinct representations can then be specified for the record types, and explicit conversion between the types can be used to effect a change in representation.]

The language does not allow implicit copying of by-reference types, so it also does not allow different representations of related by-reference types. Similarly, language rules prevent related tagged types from having different representations of the parent part. Therefore, this technique cannot be used for tagged or by-reference types.



Example of change of representation:

-- Packed_Descriptor and Descriptor are two different types
-- with identical characteristics, apart from their
-- representation
5type Descriptor is
      -- components of a descriptor
    end record;
6type Packed_Descriptor is new Descriptor;
7for Packed_Descriptor use
      -- component clauses for some or for all components
    end record;
8-- Change of representation can now be accomplished by explicit type conversions:
9D : Descriptor;
P : Packed_Descriptor;
10P := Packed_Descriptor(D);  -- pack D
D := Descriptor(P);         -- unpack P