From: "Chad R. Meiners" <chad.rmeiners@gmail.com>
Subject: Tail Recursion (Why it appears that Gnat 3.15p does support it)
Date: 13 Jan 2005 14:04:47 -0800
Date: 2005-01-13T14:04:47-08:00 [thread overview]
Message-ID: <1105653887.848989.268410@z14g2000cwz.googlegroups.com> (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
next reply other threads:[~2005-01-13 22:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-13 22:04 Chad R. Meiners [this message]
2005-01-14 8:32 ` Tail Recursion (Why it appears that Gnat 3.15p does support it) 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox