1

2

3

3.a

4

A
*range* has a *lower bound* and an *upper bound* and specifies
a subset of the values of some scalar type (the *type of the range*).
A range with lower bound L and upper bound R is described by “L
.. R”. If R is less than L, then the range
is a *null range*, and specifies an empty set of values. Otherwise,
the range specifies the values of the type from the lower bound to the
upper bound, inclusive. A value *belongs* to
a range if it is of the type of the range, and is in the subset of values
specified by the range. A value *satisfies*
a range constraint if it belongs to the associated range. One
range is *included* in another if all values that belong to the
first range also belong to the second.

5

For a subtype_indication
containing a range_constraint,
either directly or as part of some other scalar_constraint,
the type of the range
shall resolve to that of the type determined by the subtype_mark
of the subtype_indication.
For a range
of a given type, the simple_expressions
of the range
(likewise, the simple_expressions
of the equivalent range
for a range_attribute_reference)
are expected to be of the type of the range.

5.a

5.b

We say "the expected type is ..."
or "the type is expected to be ..." depending on which reads
better. They are fundamentally equivalent, and both feed into the type
resolution rules of clause 8.6.

5.c

In some cases, it doesn't work to use expected
types. For example, in the above rule, we say that the “type of
the range
shall resolve to ...” rather than “the expected type for
the range
is ...”. We then use “expected type” for the bounds.
If we used “expected” at both points, there would be an ambiguity,
since one could apply the rules of 8.6 either
on determining the type of the range, or on determining the types of
the individual bounds. It is clearly important to allow one bound to
be of a universal type, and the other of a specific type, so we need
to use “expected type” for the bounds. Hence, we used “shall
resolve to” for the type of the range as a whole. There are other
situations where “expected type” is not quite right, and
we use “shall resolve to” instead.

6

The *base range* of a scalar
type is the range of finite values of the type that can be represented
in every unconstrained object of the type; it is also the range supported
at a minimum for intermediate values during the evaluation of expressions
involving predefined operators of the type.

6.a

6.b

6.c

6.d

7

[A constrained
scalar subtype is one to which a range constraint applies.] The
*range* of a constrained scalar subtype is the range associated
with the range constraint of the subtype. The *range* of an unconstrained
scalar subtype is the base range of its type.

8

A range is *compatible*
with a scalar subtype if and only if it is either a null range or each
bound of the range belongs to the range of the subtype. A
range_constraint
is *compatible* with a scalar subtype if and only if its range is
compatible with the subtype.

8.a

9

The elaboration of a range_constraint
consists of the evaluation of the range.
The evaluation of a range
determines a lower bound and an upper bound. If simple_expressions
are given to specify bounds, the evaluation of the range
evaluates these simple_expressions
in an arbitrary order, and converts them to the type of the range.
If a range_attribute_reference
is given, the evaluation of the range
consists of the evaluation of the range_attribute_reference.

10

11

For every scalar subtype
S, the following attributes are defined:

12

S'First

12.a

13

S'Last

13.a

14

S'Range

15

S'Base

S'Base denotes an unconstrained
subtype of the type of S. This unconstrained subtype is called the *base
subtype* of the type.

16

S'Min

17

18

The function returns the lesser of the
values of the two parameters.

18.a

19

S'Max

20

21

The function returns the greater of the
values of the two parameters.

22

S'Succ

23

24

For an enumeration
type, the function returns the value whose position number is one more
than that of the value of *Arg*; Constraint_Error
is raised if there is no such value of the type. For an integer type,
the function returns the result of adding one to the value of *Arg*.
For a fixed point type, the function returns the result of adding *small*
to the value of *Arg*. For a floating point type, the function returns
the machine number (as defined in 3.5.7)
immediately above the value of *Arg*; Constraint_Error
is raised if there is no such machine number.

24.a

25

S'Pred

26

27

For an enumeration
type, the function returns the value whose position number is one less
than that of the value of *Arg*; Constraint_Error
is raised if there is no such value of the type. For an integer type,
the function returns the result of subtracting one from the value of
*Arg*. For a fixed point type, the function returns the result of
subtracting *small* from the value of *Arg*. For a floating
point type, the function returns the machine number (as defined in 3.5.7)
immediately below the value of *Arg*; Constraint_Error
is raised if there is no such machine number.

27.a

27.1/2

S'Wide_Wide_Image

27.2/2

27.3/2

The
function returns an *image* of the value of *Arg*, that is,
a sequence of characters representing the value in display form.
The lower bound of the result is one.

27.4/2

The image of an integer
value is the corresponding decimal literal, without underlines, leading
zeros, exponent, or trailing spaces, but with a single leading character
that is either a minus sign or a space.

27.b/2

27.5/2

The
image of an enumeration value is either the corresponding identifier
in upper case or the corresponding character literal (including the two
apostrophes); neither leading nor trailing spaces are included. For a
*nongraphic character* (a value of a character type that has no
enumeration literal associated with it), the result is a corresponding
language-defined name in upper case (for example, the image of the nongraphic
character identified as *nul* is “NUL” — the quotes
are not part of the image).

27.c/2

27.6/2

The image of a floating
point value is a decimal real literal best approximating the value (rounded
away from zero if halfway between) with a single leading character that
is either a minus sign or a space, a single digit (that is nonzero unless
the value is zero), a decimal point, S'Digits–1 (see 3.5.8)
digits after the decimal point (but one if S'Digits is one), an upper
case E, the sign of the exponent (either + or –), and two or more
digits (with leading zeros if necessary) representing the exponent. If
S'Signed_Zeros is True, then the leading character is a minus sign for
a negatively signed zero.

27.d/2

27.e/2

27.f/2

27.7/2

The image of a fixed
point value is a decimal real literal best approximating the value (rounded
away from zero if halfway between) with a single leading character that
is either a minus sign or a space, one or more digits before the decimal
point (with no redundant leading zeros), a decimal point, and S'Aft (see
3.5.10) digits after the decimal point.

27.g/2

27.h/2

27.i/2

28

S'Wide_Image

29

30/3

{*AI95-00285-01*}
{*AI05-0262-1*}
{*AI05-0264-1*}
The function returns an image* image*
of the value of *Arg* as a Wide_String,
that is, a sequence of characters representing the value in display form.
The lower bound of the result is one. The image
has the same sequence of graphic characters character as defined for S'Wide_Wide_Image if all the graphic characters are defined
in Wide_Character; otherwise, the sequence of characters is implementation defined (but no shorter
than that of S'Wide_Wide_Image for the same value of Arg).

30.a/2

31/2

{*AI95-00285-01*}
The image of an integer value is the corresponding
decimal literal, without underlines, leading zeros, exponent, or trailing
spaces, but with a single leading character that is either a minus sign
or a space.

31.a/2

32/2

{*AI95-00285-01*}
The image of an enumeration
value is either the corresponding identifier in upper case or the corresponding
character literal (including the two apostrophes); neither leading nor
trailing spaces are included. For a *nongraphic character* (a value
of a character type that has no enumeration literal associated with it),
the result is a corresponding language-defined or implementation-defined
name in upper case (for example, the image of the nongraphic character
identified as *nul* is “NUL” — the quotes are
not part of the image).

32.a/2

33/2

{*AI95-00285-01*}
The image of a floating point value is a decimal
real literal best approximating the value (rounded away from zero if
halfway between) with a single leading character that is either a minus
sign or a space, a single digit (that is nonzero unless the value is
zero), a decimal point, S'Digits–1 (see 3.5.8)
digits after the decimal point (but one if S'Digits is one), an upper
case E, the sign of the exponent (either + or –), and two or more
digits (with leading zeros if necessary) representing the exponent. If
S'Signed_Zeros is True, then the leading character is a minus sign for
a negatively signed zero.

33.a/2

33.b/2

33.c/2

34/2

{*AI95-00285-01*}
The image of a fixed point value is a decimal real
literal best approximating the value (rounded away from zero if halfway
between) with a single leading character that is either a minus sign
or a space, one or more digits before the decimal point (with no redundant
leading zeros), a decimal point, and S'Aft (see 3.5.10)
digits after the decimal point.

34.a/2

34.b/2

34.c/2

35

S'Image

36

37/3

{*AI95-00285-01*}
{*AI05-0264-1*}
The function returns an image of the value of *Arg* as a String.
The lower bound of the result is one. The image has the same sequence
of graphic characters as that defined for S'Wide_Wide_Image Wide_Image
if all the graphic characters are defined in Character; otherwise,
the sequence of characters is implementation defined (but no shorter
than that of S'Wide_Wide_Image Wide_Image
for the same value of *Arg*).

37.a/2

37.1/2

S'Wide_Wide_Width

{

38

S'Wide_Width

S'Wide_Width denotes the maximum
length of a Wide_String returned by S'Wide_Image over all values of the
subtype S. It denotes zero for a subtype that has a null range. Its type
is *universal_integer*.

39

S'Width

S'Width denotes the maximum length
of a String returned by S'Image over all values of the subtype S. It
denotes zero for a subtype that has a null range. Its type is *universal_integer*.

39.1/2

S'Wide_Wide_Value

39.2/2

39.3/2

This function returns
a value given an image of the value as a Wide_Wide_String, ignoring any
leading or trailing spaces.

39.4/3

{*AI05-0264-1*}
For the
evaluation of a call on S'Wide_Wide_Value for an enumeration subtype
S, if the sequence of characters of the parameter (ignoring leading and
trailing spaces) has the syntax of an enumeration literal and if it corresponds
to a literal of the type of S (or corresponds to the result of S'Wide_Wide_Image
for a nongraphic character of the type), the result is the corresponding
enumeration value; otherwise, Constraint_Error is raised.

39.a.1/2

39.a.2/2

39.5/3

{*AI05-0264-1*}
For the evaluation of a call
on S'Wide_Wide_Value for an integer subtype S, if the sequence of characters
of the parameter (ignoring leading and trailing spaces) has the syntax
of an integer literal, with an optional leading sign character (plus
or minus for a signed type; only plus for a modular type), and the corresponding
numeric value belongs to the base range of the type of S, then that value
is the result; otherwise, Constraint_Error is raised.

39.a.3/2

39.6/2

For
the evaluation of a call on S'Wide_Wide_Value for a real subtype S, if
the sequence of characters of the parameter (ignoring leading and trailing
spaces) has the syntax of one of the following:

39.7/2

39.8/2

39.9/2

39.10/2

39.11/2

39.12/3

{*AI05-0264-1*}
with an optional leading sign
character (plus or minus), and if the corresponding numeric value belongs
to the base range of the type of S, then that value is the result; otherwise, Constraint_Error is raised. The sign of a zero value is preserved (positive
if none has been specified) if S'Signed_Zeros is True.

40

S'Wide_Value

41

42

This function returns a value given an
image of the value as a Wide_String, ignoring any leading or trailing
spaces.

43/3

{*AI95-00285-01*}
{*AI05-0264-1*}
For the evaluation of a call
on S'Wide_Value for an enumeration subtype S, if the sequence of characters
of the parameter (ignoring leading and trailing spaces) has the syntax
of an enumeration literal and if it corresponds to a literal of the type
of S (or corresponds to the result of S'Wide_Image for a value nongraphic
character of the type), the result is the corresponding enumeration
value; otherwise,
Constraint_Error is raised. For a numeric subtype
S, the evaluation of a call on S'Wide_Value with *Arg* of type Wide_String
is equivalent to a call on S'Wide_Wide_Value for a corresponding *Arg*
of type Wide_Wide_String.

43.a/2

43.a.1/2

43.b/2

44/2

{*AI95-00285-01*}
For the evaluation of a call
on S'Wide_Value (or S'Value) for an integer subtype S, if the sequence
of characters of the parameter (ignoring leading and trailing spaces)
has the syntax of an integer literal, with an optional leading sign character
(plus or minus for a signed type; only plus for a modular type), and
the corresponding numeric value belongs to the base range of the type
of S, then that value is the result; otherwise
Constraint_Error is raised.

44.a/2

45/2

For
the evaluation of a call on S'Wide_Value (or S'Value) for a real subtype
S, if the sequence of characters of the parameter (ignoring leading and
trailing spaces) has the syntax of one of the following:

46/2

47/2

48/2

49/2

50/2

51/2

with
an optional leading sign character (plus or minus), and if the corresponding
numeric value belongs to the base range of the type of S, then that value
is the result; otherwise Constraint_Error
is raised. The sign of a zero value is preserved (positive if none has
been specified) if S'Signed_Zeros is True.

52

S'Value

53

54

This function returns a value given an
image of the value as a String, ignoring any leading or trailing spaces.

55/3

{*AI95-00285-01*}
{*AI05-0264-1*}
For the evaluation of a call
on S'Value for an enumeration subtype S, if the sequence of characters
of the parameter (ignoring leading and trailing spaces) has the syntax
of an enumeration literal and if it corresponds to a literal of the type
of S (or corresponds to the result of S'Image for a value of the type),
the result is the corresponding enumeration value; otherwise,
Constraint_Error is raised. For a numeric subtype S, the evaluation of
a call on S'Value with *Arg* of type String is equivalent to a call
on S'Wide_Wide_Value Wide_Value
for a corresponding *Arg* of type Wide_Wide_String Wide_String.

55.a/2

56/2

{*AI95-00285-01*}
An implementation may extend the Wide_Wide_Value,
Wide_Value, [Wide_Value,
Value, Wide_Wide_Image, Wide_Image,
and Image] attributes of a floating point type to support special values
such as infinities and NaNs.

56.a/2

56.b

56.1/3

{*AI05-0182-1*}
An implementation may extend the Wide_Wide_Value,
Wide_Value, and Value attributes of a character type to accept strings
starting with "Hex_" (ignoring case) for graphics characters
and those with a code position smaller than 16#100#, and three character
strings of the form "'*nongraphic character*'".

56.2/3

{*AI05-0228-1*}
For a scalar type, the following language-defined
representation aspect may be specified with an aspect_specification
(see 13.3.1):

56.3/3

Default_Value

This aspect shall be specified by a static expression, and that expression shall be explicit, even if the aspect has a boolean type. Default_Value shall be specified only on a full_type_declaration.

56.c/3

56.d/3

56.4/3

{*AI05-0228-1*}
If a derived type with no primitive subprograms
inherits a boolean Default_Value aspect, the aspect may be specified
to have any value for the derived type.

56.e/3

56.5/3

{*AI05-0228-1*}
The expected type for the expression
specified for the Default_Value aspect is the type defined by the full_type_declaration
on which it appears.

NOTES

57

24 The evaluation of S'First or S'Last
never raises an exception. If a scalar subtype S has a nonnull range,
S'First and S'Last belong to this range. These values can, for example,
always be assigned to a variable of subtype S.

57.a

58

25 For a subtype of a scalar type, the
result delivered by the attributes Succ, Pred, and Value might not belong
to the subtype; similarly, the actual parameters of the attributes Succ,
Pred, and Image need not belong to the subtype.

59

26 For any value V (including any nongraphic
character) of an enumeration subtype S, S'Value(S'Image(V)) equals V,
as do does
S'Wide_Value(S'Wide_Image(V)) and S'Wide_Wide_Value(S'Wide_Wide_Image(V)).
None of these expressions Neither
expression ever raise raises
Constraint_Error.

60

61

-10 .. 10

X .. X + 1

0.0 .. 2.0*Pi

Red .. Green --* see 3.5.1*

1 .. 0 --* a null range*

Table'Range --* a range attribute reference (see 3.6)*

X .. X + 1

0.0 .. 2.0*Pi

Red .. Green --

1 .. 0 --

Table'Range --

62

63

63.a/1

S'Base is no longer defined
for nonscalar types. One conceivable existing use of S'Base for nonscalar
types is S'Base'Size where S is a generic formal private type. However,
that is not generally useful because the actual subtype corresponding
to S might be a constrained array or discriminated type, which would
mean that S'Base'Size might very well overflow (for example, S'Base'Size
where S is a constrained subtype of String will generally be 8 * (Integer'Last
+ 1)). For derived discriminated types that are packed, S'Base'Size might
not even be well defined if the first subtype is constrained, thereby
allowing some amount of normally required “dope” to have
been squeezed out in the packing. Hence our conclusion is that S'Base'Size
is not generally useful in a generic, and does not justify keeping the
attribute Base for nonscalar types just so it can be used as a prefix prefix.

63.b

The attribute S'Base for
a scalar subtype is now permitted anywhere a subtype_mark
is permitted. S'Base'First .. S'Base'Last is the base range of the type.
Using an attribute_definition_clause,
one cannot specify any subtype-specific attributes for the subtype denoted
by S'Base (the base subtype).

63.c

The attribute S'Range is now allowed for scalar
subtypes.

63.d

The attributes S'Min and S'Max are now defined,
and made available for all scalar types.

63.e

The attributes S'Succ, S'Pred, S'Image, S'Value,
and S'Width are now defined for real types as well as discrete types.

63.f

Wide_String versions of S'Image and S'Value
are defined. These are called S'Wide_Image and S'Wide_Value to avoid
introducing ambiguities involving uses of these attributes with string
literals.

63.g

We now use the syntactic category range_attribute_reference
since it is now syntactically distinguished from other attribute references.

63.h

The definition of S'Base has been moved here
from 3.3.3 since it now applies only to scalar types.

63.i

More explicit rules are provided for nongraphic
characters.

63.j/2

{*AI95-00285-01*}
The attributes Wide_Wide_Image,
Wide_Wide_Value, and Wide_Wide_Width are new. Note that Wide_Image and
Wide_Value are now defined in terms of Wide_Wide_Image and Wide_Wide_Value,
but the image of types other than characters have not changed.

63.k/2

{*AI95-00285-01*}
The Wide_Image and Wide_Value attributes are now
defined in terms of Wide_Wide_Image and Wide_Wide_Value, but the images
of numeric types have not changed.

63.l/3

{*AI05-0181-1*}
**Correction:** Soft hyphen
(position 173) is nongraphic in ISO/IEC 10646:2003. Thus, we have given
it the language-defined name *soft_hyphen*. This changes the result
of Character'Image (and all of the related types and Image attributes)
for this character, and changes the behavior of Character'Value (and
all of the related types and Value attributes) for this character, and
(in unusual circumstances), changes the result for Character'Width (and
all of the related types and Width attributes). The vast majority of
programs won't see any difference, as they are already prepared to handle
nongraphic characters.

63.m/3

{*AI05-0182-1*}
**Correction:** Added an Implementation Permissions
to let Wide_Wide_Value, Wide_Value, and Value accept strings in the form
of literals containing non-graphic characters and "Hex_hhhhhhhh"
for Latin-1 and graphic characters. These were required to raise Constraint_Error
in Ada 2005. Since these attributes aren't very useful, implementations
were inconsistent as to whether these were accepted, and code that would
care why the attribute failed seems unlikely, this should not be a problem
in practice.

63.n/3

{*AI05-0228-1*}
The new aspect Default_Value
allows defining implicit initial values (see 3.3.1)
for scalar types.

Ada 2005 and 2012 Editions sponsored in part by **Ada-Europe**