7.4 Deferred Constants
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[Deferred constant declarations may be used to declare constants in the visible part of a package, but with the value of the constant given in the private part. They may also be used to declare constants imported from other languages (see Annex B).]
Legality Rules
2/3[ A deferred constant declaration is an object_declaration
with the reserved word constant but no initialization expression.] The constant declared by a deferred constant declaration is called a deferred constant. [Unless the Import aspect (see B.1) is True for a deferred constant declaration, the] deferred constant declaration requires a completion, which shall be a full constant declaration (called the full declaration of the deferred constant).
A deferred constant declaration that is completed by a full constant declaration shall occur immediately within the visible part of a package_specification
. For this case, the following additional rules apply to the corresponding full declaration:
- The full declaration shall occur immediately within the private part of the same package;
- The deferred and full constants shall have the same type, or shall have statically matching anonymous access subtypes;
subtype_indication
or access_definition
rather than an array_type_definition
, because each array_type_definition
would define a new type. - If the deferred constant declaration includes a
subtype_indication
S that defines a constrained subtype, then the constraint defined by thesubtype_indication
in the full declaration shall match the constraint defined by S statically.[ On the other hand, if the subtype of the deferred constant is unconstrained, then the full declaration is still allowed to impose a constraint. The constant itself will be constrained, like all constants;] 7/2 - If the deferred constant declaration includes the reserved word aliased, then the full declaration shall also;
- If the subtype of the deferred constant declaration excludes null, the subtype of the full declaration shall also exclude null.
subtype_indication
, as anonymous access types are required to statically match (which includes any null_exclusion
). [A deferred constant declaration for which the Import aspect is True can appear anywhere that an object_declaration
is allowed , and has no full constant declaration.]
The completion of a deferred constant declaration shall occur before the constant is frozen (see 13.14).
Dynamic Semantics
10/3The elaboration of a deferred constant declaration elaborates the subtype_indication
, access_definition
, or (only allowed in the case of an imported constant) the array_type_definition
.
subtype_indication
has to be indefinite or statically match that of the full constant, meaning that either it is a subtype_mark
or it has static constraints. If the deferred constant instead has an access_definition
, the designated subtype must be a subtype_mark
. We still say that these are elaborated, however, because part of elaboration is creating the type, which is clearly needed for access_definition
s. (A deferred constant and its full constant have different types when they are specified by an access_definition
, although there is no visible effect of these types being different as neither can be named.) full_type_declaration
. This is a consequence of the freezing rules for types (see 13.14). Examples
12Examples of deferred constant declarations:
Null_Key : constant Key; -- see 7.3.1
14/3CPU_Identifier : constant String(1..8)
with Import => True, Convention => Assembler, Link_Name => "CPU_ID";
-- see B.1
Extensions to Ada 83
pragma
Import. Such a deferred constant declaration need not be within a package_specification
.Wording Changes from Ada 83
object_declaration
s.