From: convergence82 <tiamiata@gmail.com>
Subject: Re: (Num_Types.Mod_4 range 1..8) ------->why not (1..8)?
Date: Mon, 18 May 2009 14:12:22 -0700 (PDT)
Date: 2009-05-18T14:12:22-07:00 [thread overview]
Message-ID: <8e643a98-5863-4acc-9aee-6a8fc0fde514@h23g2000vbc.googlegroups.com> (raw)
In-Reply-To: 4a11cae4$0$32667$9b4e6d93@newsspool2.arcor-online.net
On May 18, 4: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.
>
> In addition, if you choose "Integer range 1 .. 8" for
> the index type (as per Bob's suggestion) the normal
> representation of values of type integer may be
> different from that of values of type Mod_4.
> I imagine that even the instructions generated for indexing
> may be different, e.g. indicating different register word
> sizes for smaller or larger types. So Unchecked_Conversion
> may yield unexpected results.
>
> You can think of Ada arrays as tables where the keys
> are values taken from the Index type. The keys will
> not be strings, though, but either numbers, or letters,
> or enumeration literals. Maybe this helps to see why
> one array is not like the other.
>
> > 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;
>
> > I would think that the way the array is indexed is (integer, mod_4, or
> > whatever) wouldn't matter (it's the datatype of the elements of the
> > array that matter).
>
> No, that's not true for Ada arrays. Imagine
> some book pages numbered i, ii, iii, iv, ...
> while some others are numbered 1, 2, 3, 4, ...
> Book printers will carefully observe this difference:
> preface, TOC, etc. numbered i, ii, ... and then
> the book's "proper text", numbered 1, 2, ...
> This difference can be mapped to arrays index types,
> reducing the risk of mixing the sequences of book
> pages.
>
> > So, will the convert function really in effect DO NOTHING but copy the
> > data over?
>
> It shouldn't have to copy at all, that's the point :-)
Thanks you guys! Maybe one of the reasons for this awkward use of
Unchecked_Conversion is plain ole "cut-n-paste". There must be 200+
data types being converted (or more), for the project I am on. So, I
WILL read your posts more thoroughly in the next day or so.
But for now, thanks for the input,
Steph
PS. Continued debate is welcome, of course!
next prev parent reply other threads:[~2009-05-18 21:12 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 [this message]
2009-05-18 21:24 ` Adam Beneschan
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