comp.lang.ada
 help / color / mirror / Atom feed
* Tail Recursion (Why it appears that Gnat 3.15p does support it)
@ 2005-01-13 22:04 Chad  R. Meiners
  2005-01-14  8:32 ` Duncan Sands
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Chad  R. Meiners @ 2005-01-13 22:04 UTC (permalink / raw)


I have noticed that Gnat 3.15p does not optimize the tail recursion in
the following program.

with Ada.Text_IO;
use  Ada.Text_IO;

procedure Tail is

type Int is mod 2**64;

procedure Fib(First, Second : Int) is
Next : constant Int := First + Second;
begin
Put(Int'Image(Next) & ", ");
Fib(Second,Next);
end Fib;

begin
Put("1, 1, ");
Fib(1,1);
end Tail;

Does anyone know why GNAT (or any other compiler) does not always reuse
stack frames for all subroutines that appear right before a return?  Is
there some requirement that prevents such naive optimizations?
Incidently, if anyone knows of a compiler that does optimize the tail
recursion for this program please let me know.
Thank you,
Chad R. Meiners




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-01-18 20:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-13 22:04 Tail Recursion (Why it appears that Gnat 3.15p does support it) Chad  R. Meiners
2005-01-14  8:32 ` Duncan Sands
2005-01-14  9:04 ` Jacob Sparre Andersen
2005-01-14 16:06 ` wojtek
2005-01-15  5:08   ` Brian May
2005-01-18 20:59 ` Chad  R. Meiners

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