On Mon, 29 Jun 1998, Glynn Clements wrote:

>Tail end recursion is central to functional languages (e.g. ML,
>Miranda, Hope, Haskell). These don't support the notion of mutable

Tail recursion is optimized out also with GCC.

Here the assembler code of this stupid program:

int call(int i)
{
        if (!i)
                return 0;
        else
                return call(i-1);
}

main()
{
        call(2);
}

08048570 <call>:
{
 8048570:       55              pushl  %ebp
 8048571:       89 e5           movl   %esp,%ebp
 8048573:       8b 45 08        movl   0x8(%ebp),%eax
        if (!i)
 8048576:       85 c0           testl  %eax,%eax
 8048578:       74 06           je     8048580 <call+0x10>
                return 0;
        else
                return call(i-1);
 804857a:       48              decl   %eax
 804857b:       eb f9           jmp    8048576 <call+0x6>
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
 804857d:       8d 76 00        leal   0x0(%esi),%esi
 8048580:       31 c0           xorl   %eax,%eax
}
 8048582:       89 ec           movl   %ebp,%esp
 8048584:       5d              popl   %ebp
 8048585:       c3              ret
 8048586:       8d 76 00        leal   0x0(%esi),%esi
 8048589:       8d bc 27 00 00  leal   0x0(%edi,1),%edi
 804858e:       00 00

Andrea[s] Arcangeli

Reply via email to