comp.lang.ada
 help / color / mirror / Atom feed
From: Per Sandberg <per.sandberg@bredband.net>
Subject: Re: Error: "could not understand bounds information on packed array"
Date: Fri, 29 May 2009 13:56:28 +0200
Date: 2009-05-29T13:56:28+02:00	[thread overview]
Message-ID: <4A1FCD6C.3070000@bredband.net> (raw)
In-Reply-To: <gvoim5$umb$1@aioe.org>

Well.
As you say stacks will be exhausted  sooner or later if you are writing 
indefinite recursive algorithms.
And of course its possible to set the upper stack limit.
The simplest way is to add "pragma Linker_Options" in your main.
As i did in your sample.
/Per

----------------
with Ada.Text_IO; use Ada.Text_IO;
procedure Testsuite is
    pragma Linker_Options ("-Wl,--stack=0x4000000");

    procedure Recursive_Call (Index : in out Integer) is
    begin
       Index := Index + 1;
       Ada.Text_IO.Put_Line (Integer'Image (Index));
       Recursive_Call (Index);
    end Recursive_Call;

begin
    declare
       I : Integer := 0;
    begin
       Recursive_Call (I);
       Ada.Text_IO.Put_Line (Integer'Image (I));
    end;
end Testsuite;
/Per

Dennis Hoppe wrote:
> Now, I am sure it is "just" a recursion issue. The following test 
> terminates after just 87.354 iterations:
> 
> 
> with Ada.Text_IO; use Ada.Text_IO;
> 
> procedure Testsuite is
> 
>   procedure Recursive_Call (Index : in out Integer) is
>   begin
>     Index := Index + 1;
>     Ada.Text_IO.Put_Line (Integer'Image (Index));
>     Recursive_Call (Index);
>   end Recursive_Call;
> 
> begin
>   declare
>     I : Integer := 0;
>   begin
>     Recursive_Call (I);
>     Ada.Text_IO.Put_Line (Integer'Image (I));
>   end;
> end Testsuite;
> 
> 
> Output:
> 
>  [..]
>  87354
> 
> raised STORAGE_ERROR : stack overflow
> 
> Well, I didn't provide a suitable base case for termination. I just 
> wanted do find out the upper bound of recursive calling.
> 
> For me, 87.354 seems to be a very low upper bound of recursion. An 
> adapted version in Java runs 519.045 recursion steps before a 
> StackOverflowError occurs on the same machine.
> 
> It is clear, that I cannot indefinitely call a procedure recursively. 
> Unfortunately, I cannot predict in advance, how many recursion steps
> my program have to proceed. How can I avoid the stack overflow in 
> recursion? Can I influence the upper bound of recursive calls, i.e the 
> size of the run-time stack?
> 
> Thank you,
>   Dennis
> 
> 



  reply	other threads:[~2009-05-29 11:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-29  0:55 Error: "could not understand bounds information on packed array" Dennis Hoppe
2009-05-29  1:13 ` Dennis Hoppe
2009-05-29 11:58   ` Dennis Hoppe
2009-05-29 11:56     ` Per Sandberg [this message]
2009-05-29 13:02     ` John B. Matthews
2009-05-29 13:46       ` Dennis Hoppe
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox