comp.lang.ada
 help / color / mirror / Atom feed
From: mazzanti@iei.pi.cnr.it (Franco Mazzanti)
Subject: Re: Valid Attribute and Unchecked Conversion
Date: 1996/10/03
Date: 1996-10-03T00:00:00+00:00	[thread overview]
Message-ID: <mazzanti-0310961844320001@131.114.200.115> (raw)


Robert I. Eachus wrote:

>    It is erroneous.  That is the point of this discussion change to:
> 
>      declare
>          type T is range 1 .. 10;
>          for T'SIZE use Integer'SIZE;
>          function To_T is new Unchecked_Conversion (Integer, T'Base);
>          O : constant T := To_T (0);
>       begin
>          if O'Valid then
>             ...
>       end;
> 
>     Now To_T returns a bit pattern that is legal for the type (T'Base),
> and the constraint check occurs on the assignment.  You never get to
> the call to O'Valid.
> 

However, we must be very careful not to generalize this approach.
E.g.  in the following very similar case:

      declare
          type T1 is new Integer range 1 .. 10;
          type T2 is new Integer range 1 .. 10;
          for T2'SIZE use T1'SIZE;
          function To_T is new Unchecked_Conversion (T1, T2'Base);
          S1:T1;  -- maybe initialized with zero
          S2:T2;
       begin
          S2:= 1;
          ...
          S2:= To_T2(S1);
          ...
          if O'Valid then
             ...
       end;

if S1 is not initialized, and has an invalid value, the call of To_T2 is
still directly erroneous (because the unchecked conversion still tries to
return an invalid scalar value!). 

It seems, in fact, that it is a generic principle in the Reference
Manual that invalid objects can be created ONLY by a missing initialization.
Once initialized, an object can no-more become "invalid". It can become,
at best, abnormal, and just storing its value in an object is erroneous.

My impression is that the safest generic approach still requires the use of 
a "Checked_Scalar_Conversion" as shown inside the previous thread
(Re: Rules for Representation of Subtypes).

Franco Mazzanti




             reply	other threads:[~1996-10-03  0:00 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-03  0:00 Franco Mazzanti [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-10-04  0:00 Valid Attribute and Unchecked Conversion Franco Mazzanti
1996-09-26  0:00 Rules for Representation of Subtypes Robert A Duff
1996-09-26  0:00 ` Larry Kilgallen
1996-09-27  0:00   ` Robert A Duff
1996-09-27  0:00     ` Mark A Biggar
1996-09-30  0:00       ` Robert A Duff
1996-10-01  0:00         ` Larry Kilgallen
1996-10-01  0:00           ` Samuel Tardieu
1996-10-01  0:00             ` Valid Attribute and Unchecked Conversion Matthew Heaney
1996-10-02  0:00               ` Robert A Duff
1996-10-04  0:00                 ` Keith Thompson
1996-10-04  0:00                   ` Robert A Duff
1996-10-04  0:00                     ` Robert Dewar
1996-10-11  0:00                       ` Norman H. Cohen
1996-10-12  0:00                         ` Robert Dewar
1996-10-06  0:00                     ` Keith Thompson
1996-10-07  0:00                       ` Robert Dewar
1996-10-09  0:00                         ` Keith Thompson
1996-10-07  0:00                     ` Ken Garlington
1996-10-08  0:00                     ` Alan Brain
1996-10-04  0:00                   ` Matthew Heaney
1996-10-07  0:00                     ` Robert Dewar
1996-10-09  0:00                       ` Keith Thompson
1996-10-07  0:00                   ` Robert Dewar
1996-10-10  0:00                     ` Ken Garlington
1996-10-11  0:00                       ` Robert Dewar
1996-10-14  0:00                         ` Keith Thompson
1996-10-14  0:00                         ` Ken Garlington
1996-10-07  0:00                   ` Kenneth Almquist
1996-10-02  0:00   ` Robert I. Eachus
1996-10-02  0:00     ` Matthew Heaney
1996-10-02  0:00   ` George Haddad
1996-10-03  0:00     ` John Herro
1996-10-04  0:00       ` Karl Cooper {46901}
1996-10-07  0:00         ` Mark A Biggar
1996-10-08  0:00           ` Robert Dewar
1996-10-05  0:00       ` Robert Dewar
1996-10-06  0:00         ` Keith Thompson
1996-10-14  0:00           ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox