From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,ae8b13d4d815893c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!h23g2000vbc.googlegroups.com!not-for-mail From: convergence82 Newsgroups: comp.lang.ada Subject: Re: (Num_Types.Mod_4 range 1..8) ------->why not (1..8)? Date: Mon, 18 May 2009 14:12:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8e643a98-5863-4acc-9aee-6a8fc0fde514@h23g2000vbc.googlegroups.com> References: <0571282b-0ab8-4eee-941f-e9369f5b4518@x6g2000vbg.googlegroups.com> <4a11b8cb$0$32680$9b4e6d93@newsspool2.arcor-online.net> <6b5fe400-2564-4fc9-a5bf-f83d1e476345@q14g2000vbn.googlegroups.com> <4a11cae4$0$32667$9b4e6d93@newsspool2.arcor-online.net> NNTP-Posting-Host: 12.129.98.129 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1242681142 25904 127.0.0.1 (18 May 2009 21:12:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 18 May 2009 21:12:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h23g2000vbc.googlegroups.com; posting-host=12.129.98.129; posting-account=GUi2_woAAAC35fIdm7SYuE27jQOp7-FX User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 S1PS Xref: g2news2.google.com comp.lang.ada:5913 Date: 2009-05-18T14:12:22-07:00 List-Id: On May 18, 4:53=A0pm, Georg Bauhaus wrote: > convergence82 wrote: > > Thanks. =A0I'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. =A0An 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. =A0Hence, 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. =A0Maybe 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!