A length clause specifies an amount of storage associated with a type.
length_clause ::= for attribute use simple_expression;
The expression must be of some numeric type and is evaluated during the elaboration of the length clause (unless it is a static expression). The prefix of the attribute must denote either a type or a first named subtype. The prefix is called T in what follows. The only allowed attribute designators in a length clause are SIZE, STORAGE_SIZE, and SMALL. The effect of the length clause depends on the attribute designator:
A size specification is allowed for an access, task, or fixed point type, whether or not another form of length clause is also given for the type.
What is considered to be part of the storage reserved for a collection or for an activation of a task is implementation-dependent. The control afforded by length clauses is therefore relative to the implementation conventions. For example, the language does not define whether the storage reserved for an activation of a task includes any storage needed for the collection associated with an access type declared within the task body. Neither does it define the method of allocation for objects denoted by values of an access type. For example, the space allocated could be on a stack; alternatively, a general dynamic aliocation scheme or fixed storage could be used.
The objects allocated in a collection need not have the same size if the designated type is an unconstrained array type or an unconstrained type with discriminants. Note also that the allocator itself may require some space for internal tables and links. Hence a length clause for the collection of an access type does not always give precise control over the maximum number of allocated objects.
--assumed declarations: type MEDIUM is range 0 .. 65000; type SHORT is delta 0.01 range -100.0 .. 100.0; type DEGREE is delta 0.1 range -360.0 .. 360.0; BYTE : constant := 8; PAGE : constant := 2000; --length clauses: for COLOR'SIZE use 1*BYTE; -- see 3.5.1 for MEDIUM'SIZE use 2*BYTE; for SHORT'SIZE use 15; for CAR_NAME'STORAGE_SIZE use -- approximately 2000 cars 2000*((CAR'SIZE/SYSTEM.STORAGE_UNIT) +1); for KEYBOARD_DRIVERS'STORAGE_SIZE use 1*PAGE; for DEGREE'SMALL use 360.0/2**(SYSTEM.STORAGE_UNIT -1);
Notes on the examples:
In the length clause for SHORT, fifteen bits is the minimum necessary, since the type definition requires SHORT'SMALL=2**(-7) and SHORT'MANTISSA = 14. The length clause for DEGREE forces the model numbers to exactly span the range of the type.
References: access type, allocator, allow, array type, attribute, collection, composite type, constraint, delta of a fixed point type, derived type, designate, elaboration, entity, evaluation, expression, first named subtype, fixed point type, index subtype, integer type, must, numeric type, object, real type, record type, small of a fixed point type, static constraint, static expression, static subtype, storage unit, subcomponent, system package, task, task activation, task specification, task type, type, unconstrained array type.
Rationale references: 15.4.2 Length Clauses
Style Guide references: 5.4.3 Dynamic Data, 7.6.1 Representation Clauses
Address any questions or comments to firstname.lastname@example.org.