The default size of types is as specified in the reference manual. For objects, GNAT will generally increase the type size so that the object size is a multiple of storage units, and also a multiple of the alignment. For example
type Smallint is range 1 .. 6; type Rec is record y1 : integer; y2 : boolean; end record;
In this example,
has a size of 3, as specified by the RM rules,
but objects of this type will have a size of 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, 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. The reason for this decision, which is
in accordance with the specific note 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 objects 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**32-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.