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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Getting the index for an element in mutually referencing containers Date: Thu, 09 Mar 2017 14:45:09 +0100 Message-ID: <86o9xa36oq.fsf@gaheris.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net CotyNzPEWouAKNll/VeK+wDh6S8mAlnOQAn1mFCRvw567WlFu/ X-Orig-Path: gaheris.avalon.lan!not-for-mail Cancel-Lock: sha1:B+G/wKqYhTvoC+XFFmevY7Up10g= sha1:aKCBUKDUst6BXODQeUaO9+AG4cc= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Xref: news.eternal-september.org comp.lang.ada:33508 Date: 2017-03-09T14:45:09+01:00 List-Id: I am missing another thing: I managed to boil down the problem to the PoC code below. I want to have two objects, each with a container as a record attribute, referring to each other, and then merely get the index value of one of the two containers. Yet if I do, I get a Storage_Error exception. Code: with Ada.Containers.Indefinite_Vectors; with Ada.Containers.Indefinite_Doubly_Linked_Lists; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Test_Container is type Abstract_Person is abstract tagged null record; package Offspring is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive, Element_Type => Abstract_Person'Class); package Group is new Ada.Containers.Indefinite_Doubly_Linked_Lists (Element_Type => Abstract_Person'Class); type Person is new Abstract_Person with record Children : Offspring.Vector := Offspring.To_Vector(4); Parents : Group.List; end record; Father : Person; Child : Person; begin Child.Parents.Prepend(Father); Father.Children.Append(Child); Put(Integer(Father.Children.Find_Index(Child))); end Test_Container; This compiles OK, but on runtime throws an exception: raised STORAGE_ERROR : stack overflow or erroneous memory access Now, cyclic dependencies are tricky, so I am sure I am doing something wrong, but I can't for the life of me see what. Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.