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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,31982f45a4d88565 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-28 20:29:20 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3B131780.656B8B93@acm.org> From: Jeffrey Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: A Record Interpretation of an Array References: <3B12C9E0.5E9B06C8@earthlink.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 29 May 2001 03:29:18 GMT NNTP-Posting-Host: 209.86.205.184 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 991106958 209.86.205.184 (Mon, 28 May 2001 20:29:18 PDT) NNTP-Posting-Date: Mon, 28 May 2001 20:29:18 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net X-Received-Date: Mon, 28 May 2001 20:27:29 PDT (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:7834 Date: 2001-05-29T03:29:18+00:00 List-Id: "Marc A. Criley" wrote: > > I know what I'm going to be asking about is not defined by the language, > is non-portable, is implementation defined, etc. I'm just looking to > gather some thoughts and opinions here. > > Consider a plain, simple, fixed-length array of some type--no variants, > tagged types, unconstrained anythings, packing pragmas or > specifications. Just your plain 'ole basic array. For example, an > array (1..5) of Integer. > > If I wanted to access the contents of this array as a analogous record, > I could declare something like: > > type Record_View is > record > Field1 : Integer; > Field2 : Integer; > Field3 : Integer; > Field4 : Integer; > Field5 : Integer; > end record; > > and do an Unchecked_Conversion between the array type and this record > type. > > Is it reasonable to think this conversion (going either way) would give > sensible results? Is there a stronger basis for that answer than a > naive "reasonable to think"? This is reasonable. I can't see any reason why they would not be represented internally the same way. If you're willing to add some representation information to the record type, you could probably check this (for Record_View'Size use Array_Type'Size;). If you can also put some representation information on the array type you can ensure this. > > What if the array element type was of a record type, whose 'size > indicated an odd number of bytes? My experience has been that arrays of > such types pad out the elements, and so could one also reasonably expect > the analogous record view to equivalently pad out each such field? > Here you're getting onto thinner ice. It would be better to require identical representations here. Even if you can't add representation clauses to the array, you could still add them to a derived type: type Array_With_Representation is new Array_Type; for Array_With_Representation'Component_Size use ...; pragma Pack (Array_With_Representation); for Array_With_Representation'Size use ...; Lay out your Record_View type to use the same representation, then convert your array value to Array_With_Representation before unchecked converting it Record_View: To_Record_View (Array_With_Representation (Array_Value) ); Multidimensional arrays are just a further wrinkle to this idea. -- Jeff Carter "I blow my nose on you." Monty Python & the Holy Grail