At most one representation clause is allowed for a given type and a given aspect of its representation. Hence, if an alternative representation is needed, it is necessary to declare a second type, derived from the first, and to specify a different representation for the second type.
-- PACKED_DESCRIPTOR and DESCRIPTOR are two different types -- with identical characteristics, apart from their representation type DESCRIPTOR is record -- components of a descriptor end record; type PACKED_DESCRIPTOR is new DESCRIPTOR; for PACKED_DESCRIPTOR use record -- component clauses for some or for all components end record;
Change of representation can now be accomplished by assignment with explicit type conversions:
D : DESCRIPTOR; P : PACKED_DESCRIPTOR; P := PACKED_DESCRIPTOR (D); -- pack D D := DESCRIPTOR(P); -- unpack P
References: assignment, derived type, type, type conversion, type declaration, representation clause.
Rationale references: 15.3 Multiple Representations and Change of Representation
Style Guide references: 7.6.1 Representation Clauses
Address any questions or comments to firstname.lastname@example.org.