[comp.lang.ada] nasty language rules for fixed_type'last

linnig@skvax1.csc.ti.com (01/28/89)

I was astonished to learn that it is possible to raise an exception
by using 'FIRST or 'LAST on a fixed point type.  

Apparently, it is possible to specify a fixed point type that cannot
represent 'FIRST or 'LAST. The following is an example:


   1|PROCEDURE fixedtest IS
   2|TYPE f IS DELTA 1.0 RANGE 0.0 .. 32767.9; 
   3|
   4|x: f;
   5|BEGIN
   6| x:= f'last;
           ^1
***  1 Warn 4005: This operation will raise numeric_error at runtime because
***     of arithmetic overflow or because the result is not representable in
***     the target type format 
   7|END;
[TARTAN Ada VMS/1750A, Version V2.05]

The following paragraphs from the Ada LRM (3.5.9 and Appendix A) seems to
allow this behavior:

    "For a fixed point constraint that includes a range constraint, the
    model numbers comprise zero and all multiples of small whose mantissa
    can be expressed using exactly B binary digits, where the value of B is
    chosen as the smallest integer number for which each bound of the
    specified range is either a model number or lies at most small distant
    from a model number."

    "P'FIRST      For a prefix P that denotes a scalar type, or  a  subtype
                  of a scalar type:
                  Yields the lower bound of P.  The value of this attribute
                  has the same type as P.  (See 3.5.)"

For the language to allow 'FIRST and 'LAST to raise exceptions seems
very dangerous.  At least (for this example) it can be caught at compile
time.

	Mike Linnig,
	Texas Instruments

Goodenough@sei.cmu.edu (01/30/89)

In article nasty language rules for fixed_type'last of 27 Jan 89 16:24:00 GMT
linnig@skvax1.csc.ti.com writes:

>I was astonished to learn that it is possible to raise an exception
>by using 'FIRST or 'LAST on a fixed point type.  

Ada Commentary AI-00174 forbids an implementation from raising an exception
due to the evaluation of 'LAST or due to an assignment operation like that
given in your example.  This commentary has been approved by the Ada
Rapporteur Group and is to be considered for approval by the ISO standards
group for Ada (WG9) at its next meeting in June 1989.

John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391