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-31 05:47:25 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3B16306C.48347CB4@earthlink.net> From: "Marc A. Criley" Organization: Quadrus Corporation X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-5.0 i686) 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: Thu, 31 May 2001 12:47:23 GMT NNTP-Posting-Host: 63.178.180.35 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 991313243 63.178.180.35 (Thu, 31 May 2001 05:47:23 PDT) NNTP-Posting-Date: Thu, 31 May 2001 05:47:23 PDT X-Received-Date: Thu, 31 May 2001 05:45:32 PDT (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:7924 Date: 2001-05-31T12:47:23+00:00 List-Id: Keith Thompson wrote: > > "Marc A. Criley" writes: > > > 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 will often work, but it's not guaranteed. In fact, I know of an > Ada 83 implementation (some versions of TeleSoft's TeleGen2/RISCAda) > that would reorder record components, even if they're all of the same > type. It normally reordered record components to minimize gaps; for > example, it would try to put components with stricter alignment > requirements first. In the initial implementation, it used an > unstable sort (one that would not maintain the original ordering for > elements with equal keys -- I think it was a straight Quicksort), so > your Record_View might be ordered something like Field3, Field5, > Field2, Field4, Field1. Since all the array elements/record fields in this pathology are of the same type (therefore size), there should be no reason for a modern compiler to reorder them. > You might have a better chance of getting away with it if you use > something like "pragma Convention(C, Record_View);". That can't hurt... > Of course the most reliable way is to completely specify the layout > yourself, but then you're overriding the compiler's knowledge of what > layout is most efficient. I can't touch the original array declaration, but via ASIS I've got extensive access to its semantic, and much of its layout, information. Utilizing that I can build and constrain the corresponding record's character. Marc