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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Generic Embedded List Nodes Date: Tue, 21 Jun 2016 08:52:47 +0300 Organization: Tidorum Ltd Message-ID: References: <66c14298-c62d-4f4b-b0c0-e969454f9334@googlegroups.com> <2e39857a-7121-476b-807a-d2bff1e598f4@googlegroups.com> <431af616-7df3-4e4d-9262-26ed68cb74c7@googlegroups.com> <037df2b8-b9c4-4447-87ee-cc89d7072b30@googlegroups.com> <15914c54-191c-4f37-b754-282855d1aeaf@googlegroups.com> <3e25c9a0-469c-4487-b78e-6f87434f87fa@googlegroups.com> <2e69ca6f-484c-4d58-b0fe-d17a744b1418@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net PbW/aaTAJK3EqIUz0VnmCAcuVHnyXXdVCfX6QGcaoStm4TYqTZ Cancel-Lock: sha1:Hb4cnLSIikC8PjcflFpUzMEaKUc= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 In-Reply-To: <2e69ca6f-484c-4d58-b0fe-d17a744b1418@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:30850 Date: 2016-06-21T08:52:47+03:00 List-Id: On 16-06-21 05:20 , Warren wrote: > On Monday, 20 June 2016 15:33:16 UTC-4, Niklas Holsti wrote: >> On 16-06-20 15:26 , Warren wrote: >> >>> Anyway folks- thanks for your help but I now have a working solution. I'm signing off this thread. >> >> Before signing off, do please describe your solution. > > I thought I had the problem licked using the following generic > Object_Of function, but when I whipped up an example, the compile > problem returned (or there was pilot error): > > function Object_Of( > Node: access Emb_Node; > Member: Natural > ) return Object_Type is > use System.Storage_Elements; > > A: constant System.Address := Node.all'Address; > B: constant System.Address := A - Storage_Offset(Member); > R: Object_Type; > for R'Address use B; > pragma Import(Convention => Ada, Entity => R); > begin > return R; > end Object_Of; > > The compiler is complaining with: > > warning: controlled object "R" must not be overlaid. The component My_Recd.Name, of the controlled type Unbounded_String, is making Object_Type also controlled. I well understand that the compiler does not want controlled objects to be overlaid with address clauses. Instead of a function returning Object_Type, you could try returning an access to Object_Type, as produced by an instance of System.Address_To_Access_Conversions. In fact, if I understand your goals, you do not want Object_Of to return a _copy_ of the object containing the Emb_Node, the need is to _find_ that very object. Returning an access value is closer to what you want, I believe. > The test record looks like this: > > type My_Recd is > record > ID: Natural; > Node: aliased Emb_Node; > Name: Unbounded_String; > end record; If you don't get the address arithmetic to work, I believe that a set of mixin-generics could be used to add as many embedded Emb_Nodes to a tagged limited record, with access discriminants pointing to the containing record. This would eliminate the address arithmetic, at the cost of increasing the size of the record by the sizes of the discriminants (not a great deal). -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .