From: hreba <f_hreba@yahoo.com.br>
Subject: Re: storage error: stack overflow
Date: Tue, 18 Aug 2015 09:23:53 -0300
Date: 2015-08-18T09:23:53-03:00 [thread overview]
Message-ID: <d3gmeqFjf8tU1@mid.individual.net> (raw)
In-Reply-To: <b151c5a6-3acb-46c4-83cf-b2d6a5e8003c@googlegroups.com>
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
next prev parent reply other threads:[~2015-08-18 12:23 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 21:53 storage error: stack overflow hreba
2015-08-11 22:19 ` Jeffrey R. Carter
2015-08-12 15:01 ` hreba
2015-08-12 16:00 ` AdaMagica
2015-08-12 17:51 ` Jeffrey R. Carter
2015-08-13 2:17 ` hreba
2015-08-12 8:27 ` briot.emmanuel
2015-08-13 1:34 ` hreba
2015-08-13 2:53 ` Jeffrey R. Carter
2015-08-13 7:05 ` Simon Wright
2015-08-14 13:53 ` hreba
2015-08-14 16:01 ` Simon Wright
2015-08-14 17:00 ` Simon Wright
2015-08-13 7:19 ` Simon Wright
2015-08-14 13:20 ` hreba
2015-08-12 10:31 ` Markus Schöpflin
2015-08-13 1:36 ` hreba
2015-08-12 10:57 ` Simon Wright
2015-08-13 0:55 ` hreba
2015-08-13 6:58 ` Simon Wright
2015-08-18 2:16 ` hreba
2015-08-18 5:49 ` Jeffrey R. Carter
2015-08-18 7:24 ` Egil H H
2015-08-18 12:23 ` hreba [this message]
2015-08-18 12:37 ` Jacob Sparre Andersen
2015-08-18 14:02 ` hreba
2015-08-18 14:11 ` Dmitry A. Kazakov
2015-08-18 14:16 ` Jeffrey R. Carter
2015-08-18 20:56 ` Randy Brukardt
2015-08-19 1:48 ` hreba
2015-08-19 5:10 ` Jeffrey R. Carter
2015-08-19 8:44 ` Georg Bauhaus
2015-08-19 11:56 ` hreba
2015-08-19 20:53 ` Bob Duff
2015-08-18 14:15 ` Egil H H
2015-08-19 13:07 ` hreba
2015-08-18 14:16 ` Jeffrey R. Carter
2015-08-19 13:12 ` hreba
2015-08-19 20:47 ` Bob Duff
2015-08-19 21:47 ` Jeffrey R. Carter
2015-08-20 7:18 ` Dmitry A. Kazakov
2015-08-20 20:48 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox