comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: storage error: stack overflow
Date: Tue, 18 Aug 2015 15:56:04 -0500
Date: 2015-08-18T15:56:04-05:00	[thread overview]
Message-ID: <mr0655$u2f$1@loke.gir.dk> (raw)
In-Reply-To: mqvejr$hai$2@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:mqvejr$hai$2@dont-email.me...
> On 08/18/2015 07:02 AM, hreba wrote:
>>
>> Huh? As much as I know you cannot declare variables of a type with 
>> unknown
>> storage requirements at compile time, such as class-wide types and arrays 
>> with
>> unknown range.
>
> These are "indefinite types". You can declare an object of an indefinite 
> type as
> long as you supply an initialization expression:
>
> S : String := "Hello";
>
> V : T'Class := Some_Function;

And if you need to change the type of the object after initialization, you 
can use the "Holder" container, which exists for this very purpose:

      package T_Class_Holder is new Ada.Containers.Indefinite_Holders 
(T'Class);

      V : T_Class_Holder.Holder;
  begin
      V.Replace_Element (Some_Function);
      ...
      V.Replace_Element (Some_Other_Function);
      ...
   end;

In Ada 2012, you can also use the reference function to modify the object, 
but you can't change the tag that way. That is:

    V.Reference := Some_Function;

As noted, this will raise Constraint_Error if the tag of V.Reference is 
changed.

I may sound like a broken record (scratched CD?? ;-), but using a Holder 
rather than explicit access types lets the library do the storage management 
rather than the programmer. There are much less likely to be bugs that way.

And of course, you can do this with all of the containers; if you need a Map 
or Tree or Vector [including an array] of T'Class, just instantiate the 
appropriate container and again let someone at your compiler vendor get the 
storage management right, rather than doing it yourself.

                                              Randy.



  reply	other threads:[~2015-08-18 20:56 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
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 [this message]
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