comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: (Num_Types.Mod_4 range 1..8) ------->why not (1..8)?
Date: Mon, 18 May 2009 14:24:23 -0700 (PDT)
Date: 2009-05-18T14:24:23-07:00	[thread overview]
Message-ID: <03cb75a1-3458-420e-9871-6f64f784c177@s38g2000prg.googlegroups.com> (raw)
In-Reply-To: 4a11cae4$0$32667$9b4e6d93@newsspool2.arcor-online.net

On May 18, 1:53 pm, Georg Bauhaus <rm.tsoh.plus-
bug.bauh...@maps.futureapps.de> wrote:
> convergence82 wrote:
> > Thanks.  I'm looking at a Ada.Unchecked_Conversion function that
> > converts from Data_Array_1 to Data_Array_2:
> > type Data_Array_1 is array (Num_Types.Mod_4 range 1..8) of
> > Num_Types.Mod_8;
> > type Data_Array_2 is array (1..8) of Num_Types.Mod_8;
>
> Uhm, converting is what instances of Unchecked_Conversion
> do *not* do, in some (paradoxical) sense.
> To convert X of type T to X of type D, write D(X).
> An instance of Unchecked_Conversion will just leave
> the bits unchanged. The programmer should then know the
> meaning of the "converted" data.  An Ada array, however,
> is a bit more than a sequence of storage cells,
> when it includes bounds an other properties of the
> corresponding array type.  Hence, arrays of different
> type may be stored differenty.

This may be true in theory but I doubt that it is true in practice.
Both array types are constrained; therefore, the representation of the
array is almost certain to be just the eight data elements strung
together.  I doubt that any existing or future Ada compiler is going
to do things any differently, or store the bounds anywhere in the
array data.  Therefore, Unchecked_Conversion is most likely going to
work.  It's a poor idea to use it, though, since a regular Ada type
conversion is legal and is 100% guaranteed to be portable (as opposed
to only 99.9999% guaranteed for Unchecked_Conversion).

A case like this is harder:

type Enum_Type is (E0, E1, E2, E3, E4, E5, E6, E7);
type Data_Array_1 is array (Enum_Type) of Num_Types.Mod_8;
type Data_Array_2 is array (1..8) of Num_Types.Mod_8;

Now an Ada type conversion won't work, and the only way to convert
from one array type to another is to use a FOR loop or an abomination
like
    (1=>A(E0), 2=>A(E1), 3=>A(E2), ...)

                                   -- Adam




  parent reply	other threads:[~2009-05-18 21:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 19:19 (Num_Types.Mod_4 range 1..8) ------->why not (1..8)? convergence82
2009-05-18 19:36 ` Georg Bauhaus
2009-05-18 19:58   ` convergence82
2009-05-18 20:50     ` Adam Beneschan
2009-05-18 20:53     ` Georg Bauhaus
2009-05-18 21:12       ` convergence82
2009-05-18 21:24       ` Adam Beneschan [this message]
2009-05-19  6:26         ` christoph.grein
2009-05-19  7:47           ` Petter
2009-05-19  8:04             ` christoph.grein
2009-05-19 13:13               ` Petter
2009-05-19 15:27                 ` Georg Bauhaus
2009-05-19 17:53           ` Adam Beneschan
2009-05-18 19:49 ` 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