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.8 required=5.0 tests=BAYES_00, GUARANTEED_100_PERCENT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s38g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: (Num_Types.Mod_4 range 1..8) ------->why not (1..8)? Date: Mon, 18 May 2009 14:24:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <03cb75a1-3458-420e-9871-6f64f784c177@s38g2000prg.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: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1242681864 9599 127.0.0.1 (18 May 2009 21:24:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 18 May 2009 21:24:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s38g2000prg.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5914 Date: 2009-05-18T14:24:23-07:00 List-Id: On May 18, 1: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. 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=3D>A(E0), 2=3D>A(E1), 3=3D>A(E2), ...) -- Adam