Annotated Ada Reference Manual (Ada 202y Draft 1)Legal Information
Contents   Index   References   Search   Previous   Next 

3.3.2 Number Declarations

1
A number_declaration declares a named number. 
1.a/5
Discussion: {AI05-0299-1} {AI12-0449-1} If a value or other property of a construct is required to be static that means it is required to be determined prior to execution. A static expression is an expression whose value is computed at compile time and is usable in contexts where the actual value might affect the legality of the construct. This is fully defined in 4.9

Syntax

2
number_declaration ::= 
     defining_identifier_list : constant := static_expression;

Name Resolution Rules

3
The static_expression given for a number_declaration is expected to be of any numeric type.
3.1/5
 {AI12-0394-1} A name that denotes a number_declaration is interpreted as a value of a universal type, unless the expected type for the name is a non-numeric type with an Integer_Literal or Real_Literal aspect, in which case it is interpreted to be of its expected type.
3.a/5
To be honest: This is only a Name Resolution Rule; all named numbers are values of a universal type (see the Static Semantics below). We need this rule so that named numbers can match types with user-defined literals; we need the other rules so the value of the named number is well-defined in all cases. 

Legality Rules

4/5
{AI05-0299-1} {AI12-0449-1} The static_expression given for a number declaration shall be a static expression, as defined by 4.9

Static Semantics

5
The named number denotes a value of type universal_integer if the type of the static_expression is an integer type. The named number denotes a value of type universal_real if the type of the static_expression is a real type.
6
The value denoted by the named number is the value of the static_expression, converted to the corresponding universal type.

Dynamic Semantics

7
The elaboration of a number_declaration has no effect. 
7.a
Proof: Since the static_expression was evaluated at compile time. 

Examples

8
Examples of number declarations: 
9
Two_Pi        : constant := 2.0*Ada.Numerics.Pi; 
                                          -- a real number (see A.5)
10/2
{AI95-00433-01} Max           : constant := 500;          -- an integer number
Max_Line_Size : constant := Max/6;        -- the integer 83
Power_16      : constant := 2**16;        -- the integer 65_536
One, Un, Eins : constant := 1;            -- three different names for 1

Extensions to Ada 83

10.a
We now allow a static expression of any numeric type to initialize a named number. For integer types, it was possible in Ada 83 to use 'Pos to define a named number, but there was no way to use a static expression of some nonuniversal real type to define a named number. This change is upward compatible because of the preference rule for the operators of the root numeric types. 

Wording Changes from Ada 83

10.b
We have moved the syntax rule into this subclause.
10.c
AI83-00263 describes the elaboration of a number declaration in words similar to that of an object_declaration. However, since there is no expression to be evaluated and no object to be created, it seems simpler to say that the elaboration has no effect.

Extensions to Ada 2012

10.d/5
{AI12-0394-1} Named numbers now can be used with (non-numeric) types that define user-defined literals (see 4.2.1).

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