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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Generic Embedded List Nodes Date: Sat, 18 Jun 2016 16:40:23 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <66c14298-c62d-4f4b-b0c0-e969454f9334@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 18 Jun 2016 23:40:30 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="48b46be33beed75863f69afa437f956b"; logging-data="25547"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OT7X02SxAV47Fd5i9Nz7YO3bagIAFK6s=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <66c14298-c62d-4f4b-b0c0-e969454f9334@googlegroups.com> Cancel-Lock: sha1:x4gw8gjpO8BPzVAhBOPzAQmTeoU= X-Enigmail-Draft-Status: N1110 Xref: news.eternal-september.org comp.lang.ada:30800 Date: 2016-06-18T16:40:23-07:00 List-Id: On 06/18/2016 03:52 PM, Warren wrote: > > The idea is that the list node resides within the structure/tagged type, > and acts as a doubly linked list node when in a list. The Emb_Node can > be used as a list head when itself (or as part of another structure). This > kind of thing is done in the Linux kernel, for example. > > The Emb_Node and its operations are trivial. The problem occurs when > you traverse a linked list of Emb_Nodes (or its derived type). With > a given node, I need to then access the object that _contains_ it. In > C/C++ you do some offset calculation from the node address back to > the owning struct/class. Let me make sure I understand this. You have type Emb_Node, and you can string Emb_Nodes together to make a list. You want to make a composite type with an Emb_Node component: type Outer is record ... Node : Emb_Node; ... end record; and declare objects of this type: O1 : Outer; O2 : Outer; type O_Set is array (Positive range <>) of Outer; O_List : O_Set (1 .. 10); type Something is record ... O : Outer; ... end record; S : Something; and then be able to string the Node components of all these Outers together into a list, and then treat that list as a list of Outers. Is that correct? -- Jeff Carter "My legs are gray, my ears are gnarled, my eyes are old and bent." Monty Python's Life of Brian 81