From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,170d8c9368cab115 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Tail Recursion (Why it appears that Gnat 3.15p does support it) Date: Fri, 14 Jan 2005 09:32:36 +0100 Organization: Cuivre, Argent, Or Message-ID: References: <1105653887.848989.268410@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1105691582 82323 212.85.156.195 (14 Jan 2005 08:33:02 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 14 Jan 2005 08:33:02 +0000 (UTC) Cc: "Chad R. Meiners" To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.7.1 In-Reply-To: <1105653887.848989.268410@z14g2000cwz.googlegroups.com> Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:7754 Date: 2005-01-14T09:32:36+01:00 Hi Chad, first I commented out the Put in Fib: begin --Put(Int'Image(Next) & ", "); Fib(Second,Next); then I compiled this with gcc from CVS as follows: > gnatmake -O2 tail gcc -c -O2 tail.adb tail.adb:12:01: warning: possible infinite recursion tail.adb:12:01: warning: Storage_Error may be raised at run time gnatbind -x tail.ali gnatlink tail.ali The disassembly is then: > objdump -r -d tail.o tail.o: file format elf32-i386 Disassembly of section .text: 00000000 : 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: eb fe jmp 3 5: 8d 74 26 00 lea 0x0(%esi),%esi 9: 8d bc 27 00 00 00 00 lea 0x0(%edi),%edi 00000010 <_ada_tail>: 10: 55 push %ebp 11: b8 08 00 00 00 mov $0x8,%eax 12: R_386_32 .rodata 16: 89 e5 mov %esp,%ebp 18: ba 00 00 00 00 mov $0x0,%edx 19: R_386_32 .rodata 1d: 83 ec 08 sub $0x8,%esp 20: 89 04 24 mov %eax,(%esp) 23: 89 54 24 04 mov %edx,0x4(%esp) 27: e8 fc ff ff ff call 28 <_ada_tail+0x18> 28: R_386_PC32 ada__text_io__put__4 2c: 31 c0 xor %eax,%eax 2e: 89 e9 mov %ebp,%ecx 30: 89 44 24 04 mov %eax,0x4(%esp) 34: 31 d2 xor %edx,%edx 36: b8 01 00 00 00 mov $0x1,%eax 3b: c7 04 24 01 00 00 00 movl $0x1,(%esp) 42: e8 b9 ff ff ff call 0 47: c9 leave 48: c3 ret which is a bit too optimised! Comments: (1) I commented out the Put because I expected the "&" (string concatenation) to cause trouble, since it uses the secondary stack. (2) Maybe the fact that Fib is a local procedure causes problems for older gcc. All the best, Duncan.