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,FREEMAIL_FROM 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!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Tue, 18 Aug 2015 09:23:53 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net RTgaX9DnzXIlqSyfoyO8hwdnEkUB6ZAj5WFd0RsSRKupsSMOc0 Cancel-Lock: sha1:BtoB82WIysySWc9RnvE+EmnJBI4= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:27487 Date: 2015-08-18T09:23:53-03:00 List-Id: On 08/18/2015 04:24 AM, Egil H H wrote: > On Tuesday, August 18, 2015 at 4:16:38 AM UTC+2, hreba wrote: >> >> with Ada.Strings.Unbounded; >> >> procedure testUBS is >> >> type TA is record >> name: Ada.Strings.Unbounded.Unbounded_String; >> end record; >> >> type TB is record >> a: TA; >> end record; >> >> function New_TB (name: String:="") return access TB is >> begin >> return new TB' >> (a=>TA'(name=>Ada.Strings.Unbounded.To_Unbounded_String(name))); >> end New_TB; >> >> b: access TB:= New_TB (name=>"Det"); >> name: Ada.Strings.Unbounded.Unbounded_String; >> >> begin >> name:= b.a.name; >> end testUBS; >> > > This fails as described with Gnat Pro 6.4.1 (GCC 4.5.2), > but seems to be fixed in later versions, at least Gnat Pro 7.1.1 (GCC 4.7.3). > > You should try to avoid anonymous access types if at all possible. I need an access type because in my real program TB is a tagged type and I need class-wide variables. As long as everything works I prefer the anonymous type because it saves me a type conversion. But I am still in doubt about the best practice, there is some discrepancy between the examples in my Ada book (Barnes) and the posts in this group. > However, you could try to work around the problem using an extended return, > like this: > > function New_TB > (Name : String := "") > return access TB > is > begin > return Foo : access TB := new TB do > foo.all := TB' > (A => TA' > (Name => Ada.Strings.Unbounded.To_Unbounded_String(Name))); > end return; > end New_TB; > Didn't know about extended return (the Ada 95 book was cheaper -:). But there is a problem: the TB in my original program is not only tagged, it is limited too (and New_TB is for initialization). So "foo.all:=..." is forbidden. -- Frank Hrebabetzky +55 / 48 / 3235 1106 Florianopolis, Brazil