comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@rfc1149.net>
Subject: Re: Project file - suggestions/help needed.
Date: Mon, 04 Aug 2008 11:17:42 +0200
Date: 2008-08-04T11:20:01+02:00	[thread overview]
Message-ID: <87sktldtqh.fsf@willow.rfc1149.net> (raw)
In-Reply-To: m2r695eonx.fsf@mac.com

>>>>> "Simon" == Simon Wright <simon.j.wright@mac.com> writes:

Simon> I wasn't able to see where the RM requires stack checking?
Simon> 8.5.4(8.1/1), for example, mentions infinite recursion as a
Simon> possibility (well, not possible really of course!)

Of course it is possible. Infinite recursion doesn't necessarily imply
infinite stack usage (think recursive tail calls and sibling tail calls).

You may want to try the program attached at the end of this post. If
you compile it with GNAT using

  gnatmake -gnato -fstack-check -O2 recurse

you will see that it executes forever. Well, you might not be able to
guarantee that it executes forever of course, but you will see using
"top" or any other system monitor that its memory usage is not
increasing over time.

The recursive call in Infinite_Recursion is a tail call, meaning the
Infinite_Recursion subprogram has been transformed into its
semantically equivalent

  loop
    Display (X'Img);
    X := X + 1;
  end loop;

--  Program starts here

with Infinite_Recursion;

procedure Recurse is
begin
  Infinite_Recursion (0);
end Recurse;

with Display;
with Interfaces; use Interfaces;

procedure Infinite_Recursion (X : Unsigned_32) is
begin
   Display (X);
   Infinite_Recursion (X+1);
end Infinite_Recursion;

with Ada.Text_IO; use Ada.Text_IO;
With Interfaces;  use Interfaces;
procedure Display (X : Unsigned_32) is
begin
   Put_Line (X'Img);
end Display;



  reply	other threads:[~2008-08-04  9:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-03  8:00 Project file - suggestions/help needed Thomas
2008-08-03 10:41 ` Simon Wright
2008-08-03 11:03 ` Stephen Leake
2008-08-03 15:22 ` Gautier
2008-08-04 20:59   ` Colin_Paul_Gloster
2008-08-03 17:13 ` Jeffrey R. Carter
2008-08-03 22:09   ` Simon Wright
2008-08-04  9:17     ` Samuel Tardieu [this message]
2008-08-04 21:05   ` Colin_Paul_Gloster
2008-08-05  5:27     ` Thomas Locke
2008-08-13 21:56       ` DScott
2008-08-03 18:43 ` Gene
2008-08-04 14:24   ` Thomas Locke
2008-08-13 21:58     ` DScott
2008-08-04 20:54 ` Colin_Paul_Gloster
2008-08-05  5:26   ` Thomas Locke
2008-08-05  8:00     ` Pascal Obry
2008-08-05  8:10       ` Thomas Locke
2008-08-05  8:05     ` Jean-Pierre Rosen
replies disabled

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