Next: , Previous: Size of Variant Record Objects, Up: Representation Clauses and Pragmas


6.5 Biased Representation

In the case of scalars with a range starting at other than zero, it is possible in some cases to specify a size smaller than the default minimum value, and in such cases, GNAT uses an unsigned biased representation, in which zero is used to represent the lower bound, and successive values represent successive values of the type.

For example, suppose we have the declaration:

        type Small is range -7 .. -4;
        for Small'Size use 2;

Although the default size of type Small is 4, the Size clause is accepted by GNAT and results in the following representation scheme:

       -7 is represented as 2#00#
       -6 is represented as 2#01#
       -5 is represented as 2#10#
       -4 is represented as 2#11#

Biased representation is only used if the specified Size clause cannot be accepted in any other manner. These reduced sizes that force biased representation can be used for all discrete types except for enumeration types for which a representation clause is given.