Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
 
Ada Reference Manual (Ada 2022 with Amendment 1)Legal Information
Contents   Index   References   Search   Previous   Next 

7.4 Deferred Constants

1
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).
3
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: 
4
The full declaration shall occur immediately within the private part of the same package;
5/2
The deferred and full constants shall have the same type, or shall have statically matching anonymous access subtypes;
6/6
If the deferred constant declaration includes a subtype_indication that defines a subtype S1, then the subtype_indication in the full declaration shall define a subtype S2 that is statically compatible with S1 (see 4.9.1). If S1 is a constrained subtype, the constraint defined by S2 shall statically match the constraint defined by S1. If the subtype S1 of the deferred constant is unconstrained, then the full declaration is still allowed to impose a constraint;
7/6
If the deferred constant declaration includes the reserved word aliased, then the full declaration shall also. 
8/5
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.
9/2
The completion of a deferred constant declaration shall occur before the constant is frozen (see 13.14).

Dynamic Semantics

10/3
The 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.
11
NOTE   The full constant declaration for a deferred constant that is of a given private type or private extension is not allowed before the corresponding full_type_declaration. This is a consequence of the freezing rules for types (see 13.14).

Examples

12
Examples of deferred constant declarations: 
13
Null_Key : constant Key;      -- see 7.3.1
14/3
CPU_Identifier : constant String(1..8)
   with Import => True, Convention => Assembler, Link_Name => "CPU_ID";
                              -- see B.1

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe