1
An object_declaration declares a stand−alone object with a given nominal subtype and, optionally, an explicit initial value given by an initialization expression. For an array, task, or protected object, the object_declaration may include the definition of the (anonymous) type of the object.
2/2
object_declaration::=
defining_identifier_list : [aliased] [constant] subtype_indication [:= expression];
| defining_identifier_list : [aliased] [constant] access_definition [:= expression];
| defining_identifier_list : [aliased] [constant] array_type_definition [:= expression];
| single_task_declaration
| single_protected_declaration
3
defining_identifier_list::=
defining_identifier {, defining_identifier}
4
For an object_declaration with an expression following the compound delimiter :=, the type expected for the expression is that of the object. This expression is called the initialization expression.
5/2
An object_declaration without the reserved word constant declares a variable object. If it has a subtype_indication or an array_type_definition that defines an indefinite subtype, then there shall be an initialization expression.
6
An object_declaration with the reserved word constant declares a constant object. If it has an initialization expression, then it is called a full constant declaration. Otherwise it is called a deferred constant declaration. The rules for deferred constant declarations are given in clause 7.4. The rules for full constant declarations are given in this subclause.
7
Any declaration that includes a defining_identifier_list with more than one defining_identifier is equivalent to a series of declarations each containing one defining_identifier from the list, with the rest of the text of the declaration copied for each declaration in the series, in the same order as the list. The remainder of this International Standard relies on this equivalence; explanations are given for declarations with a single defining_identifier.
8/2
The subtype_indication, access_definition, or full type definition of an object_declaration defines the nominal subtype of the object. The object_declaration declares an object of the type of the nominal subtype.
8.1/2
A component of an object is said to require late initialization if it has an access discriminant value constrained by a per−object expression, or if it has an initialization expression that includes a name denoting the current instance of the type or denoting an access discriminant.
9/2
If a composite object declared by an object_declaration has an unconstrained nominal subtype, then if this subtype is indefinite or the object is constant the actual subtype of this object is constrained. The constraint is determined by the bounds or discriminants (if any) of its initial value; the object is said to be constrained by its initial value. When not constrained by its initial value, the actual and nominal subtypes of the object are the same. If its actual subtype is constrained, the object is called a constrained object.
10
For an object_declaration without an initialization expression, any initial values for the object or its subcomponents are determined by the implicit initial values defined for its nominal subtype, as follows:
11
12
13
14
15
The elaboration of an object_declaration proceeds in the following sequence of steps:
16/2
17
18/2
19/2
20/2
For the third step above, evaluations and assignments are performed in an arbitrary order subject to the following restrictions:
20.1/2
20.2/2
20.3/2
20.4/2
21
There is no implicit initial value defined for a scalar subtype. In the absence of an explicit initialization, a newly created scalar object might have a value that does not belong to its subtype (see 13.9.1 and H.1).
NOTES
22
7 Implicit initial values are not defined for an indefinite subtype, because if an object's nominal subtype is indefinite, an explicit initial value is required.
23
8 As indicated above, a stand−alone object is an object declared by an object_declaration. Similar definitions apply to "stand−alone constant" and "stand−alone variable." A subcomponent of an object is not a stand−alone object, nor is an object that is created by an allocator. An object declared by a loop_parameter_specification, parameter_specification, entry_index_specification, choice_parameter_specification, or a formal_object_declaration is not called a stand−alone object.
24
9 The type of a stand−alone object cannot be abstract (see 3.9.3).
25
Example of a multiple object declaration:
26
−− the multiple object declaration
27/2
John, Paul : not null Person_Name := new Person(Sex => M); −− see 3.10.1
28
−− is equivalent to the two single object declarations in the order given
29/2
John : not null Person_Name := new Person(Sex => M); Paul : not null Person_Name := new Person(Sex => M);
30
Examples of variable declarations:
31/2
Count, Sum : Integer; Size : Integer range 0 .. 10_000 := 0; Sorted : Boolean := False; Color_Table : array(1 .. Max) of Color; Option : Bit_Vector(1 .. 10) := (others => True); Hello : aliased String := "Hi, world."; [Unicode 952] , [Unicode 966] : Float range −PI .. +PI;
32
Examples of constant declarations:
33/2
Limit : constant Integer := 10_000; Low_Limit : constant Integer := Limit/10; Tolerance : constant Real := Dispersion(1.15); Hello_Msg : constant access String := Hello'Access; −− see 3.10.2