[Home] [Prev] [Next] [Index]

13.6 Change of Representation

13.6 Change of Representation

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

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

3
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

4
References:

*
assignment 5.2

*
derived type 3.4

*
type 3.3

*
type conversion 4.6

*
type declaration 3.1

*
representation clause 13.1



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.