Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.


13.6. Change of Representation

[PREVIOUS][UP][NEXT]

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.

Example:

  -- 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

[INDEX][CONTENTS]


[Ada Information Clearinghouse]

Address any questions or comments to adainfo@sw-eng.falls-church.va.us.