comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: array conversion - how to do?
Date: 1997/06/28
Date: 1997-06-28T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.97Jun27225701@spectre.mitre.org> (raw)
In-Reply-To: 5opej8$rv5$1@gonzo.sun3.iaf.nl


In article <5opej8$rv5$1@gonzo.sun3.iaf.nl> Geert Bosch <geert@gonzo.sun3.iaf.nl> writes:

 > Here is a simple situation illustrating a problem I encountered
 > in using arrays of pointers to tagged objects. I have an
 > application that should only use printable ASCII characters in its
 > string processing. So I declare the following:

 >    subtype ASCII_Character is Character 
 >	range Character'Val (32) .. Character'Val (127);
 >     type ASCII_String is array (Positive range <>) of ASCII_Character;
 ...

 > Although this is IMHO a solution with clear semantics, this is
 > not legal Ada because of the rule that array conversions are only
 > allowed between array types that have components of the same subtype.
 > The workaround is both ugly and inefficient using a typical Ada 
 > implementation...

 > I could imagine why it would not be possible to convert String
 > to ASCII_String, since that conversion might need time-consuming
 > checks. The conversion in the example is completely safe though,
 > which is statically checkable for the compiler.

    I used to worry about the fact that doing these conversions
efficiently meant instantiating Unchecked_Conversion, but I eventually
came around to the understanding that that is exactly what is
happening here.  It is my responsibility as the Unchecked_Conversion
user to know that the conversion is correctly checked.  Easy in this
case, but this is a special case of a much more general one--the
element subtypes are not required to be static.  I still may know that
the conversion is safe, but by calling Unchecked_Conversion I am
taking that responsibility.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  parent reply	other threads:[~1997-06-28  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-24  0:00 array conversion - how to do? Geert Bosch
1997-06-27  0:00 ` Wes Groleau
1997-06-27  0:00   ` Robert Dewar
1997-06-28  0:00     ` Geert Bosch
1997-07-03  0:00       ` Robert Dewar
1997-07-04  0:00         ` Geert Bosch
1997-07-04  0:00         ` Geert Bosch
1997-07-04  0:00           ` Robert Dewar
1997-06-28  0:00 ` Robert I. Eachus [this message]
1997-06-28  0:00   ` Geert Bosch
1997-06-30  0:00     ` Robert I. Eachus
replies disabled

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