Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


13.6 Change of Representation

(1)
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 need to be declared with matching component subtypes, and convertible index types. If one type has packing specified and the other does not, then explicit conversion can be used to pack or unpack an array.
(2)
To convert a record from one representation to another, two record types with a common ancestor type need to be declared, with no inherited subprograms. 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.
Examples
(3)
Example of change of representation:
(4)
       -- Packed_Descriptor and Descriptor are two different types
       -- with identical characteristics, apart from their
       -- representation
(5)
       type Descriptor is
           record
             -- components of a descriptor
           end record;
(6)
       type Packed_Descriptor is new Descriptor;
(7)
       for Packed_Descriptor use
           record
             -- component clauses for some or for all components
           end record;
(8)
       -- Change of representation can now be accomplished by explicit type conversions:
(9)
       D : Descriptor;
       P : Packed_Descriptor;
(10)
       P := Packed_Descriptor(D);  -- pack D
       D := Descriptor(P);         -- unpack P


Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12