The default size for a type T is obtainable through the language-defined attribute T'Size and also through the equivalent GNAT-defined attribute T'Value_Size. For objects of type T, GNAT will generally increase the type size so that the object size (obtainable through the GNAT-defined attribute T'Object_Size) is a multiple of T'Alignment * Storage_Unit.
type Smallint is range 1 .. 6; type Rec is record Y1 : integer; Y2 : boolean; end record;
In this example, Smallint'Size = Smallint'Value_Size = 3, as specified by the RM rules, but objects of this type will have a size of 8 (Smallint'Object_Size = 8), since objects by default occupy an integral number of storage units. On some targets, notably older versions of the Digital Alpha, the size of stand alone objects of this type may be 32, reflecting the inability of the hardware to do byte load/stores.
Similarly, the size of type Rec is 40 bits (Rec'Size = Rec'Value_Size = 40), but the alignment is 4, so objects of this type will have their size increased to 64 bits so that it is a multiple of the alignment (in bits). This decision is in accordance with the specific Implementation Advice in RM 13.3(43):
"A Size clause should be supported for an object if the specified Size is at least as large as its subtype's Size, and corresponds to a size in storage elements that is a multiple of the object's Alignment (if the Alignment is nonzero)."
An explicit size clause may be used to override the default size by increasing it. For example, if we have:
type My_Boolean is new Boolean; for My_Boolean'Size use 32;
then values of this type will always be 32 bits long. In the case of discrete types, the size can be increased up to 64 bits, with the effect that the entire specified field is used to hold the value, sign- or zero-extended as appropriate. If more than 64 bits is specified, then padding space is allocated after the value, and a warning is issued that there are unused bits.
Similarly the size of records and arrays may be increased, and the effect is to add padding bits after the value. This also causes a warning message to be generated.
The largest Size value permitted in GNAT is 2**31-1. Since this is a Size in bits, this corresponds to an object of size 256 megabytes (minus one). This limitation is true on all targets. The reason for this limitation is that it improves the quality of the code in many cases if it is known that a Size value can be accommodated in an object of type Integer.