Tail Recursion (Why it appears that Gnat 3.15p does support it)
From: Chad R. Meiners (chad.rmeiners_at_gmail.com)
Date: 01/13/05
- Next message: Keith Thompson: "Re: How unchecked conversion works?"
- Previous message: Florian Weimer: "Re: Isnt Gnat irrelevant ? ( was Re: Will the World ever seesomethingbeyond GNAT 3.15p?)"
- Next in thread: Duncan Sands: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Duncan Sands: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Jacob Sparre Andersen: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: wojtek_at_power.com.pl: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Chad R. Meiners: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Jan 2005 14:04:47 -0800
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 message: Keith Thompson: "Re: How unchecked conversion works?"
- Previous message: Florian Weimer: "Re: Isnt Gnat irrelevant ? ( was Re: Will the World ever seesomethingbeyond GNAT 3.15p?)"
- Next in thread: Duncan Sands: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Duncan Sands: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Jacob Sparre Andersen: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: wojtek_at_power.com.pl: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Reply: Chad R. Meiners: "Re: Tail Recursion (Why it appears that Gnat 3.15p does support it)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|