Re: Tail call optimization



On Thu, 23 Jun 2005 08:27:43 +1200, Andrew Ward wrote:

> Andrew Ward wrote:
>> Hi All,
>> Could someone please tell me at what optimization level cl will produce
>> optimized tail calls for recursive functions? I.e, no stack growth.
>>
>> Thanks
>
> After a few simple tests with VC++ 7.1 it seems that tail call
> optimizations are not performed at all, even at -Ox optimization level.
> How then are you to supposed to write tail called recursive functions
> that operate over large data sets without getting a stack overflow?

Do what an optimizer does and turn it into a loop or use a goto. In any
event, relying on an optimizer to save you from stack overflow is not a
good plan.

--
Doug Harrison
Microsoft MVP - Visual C++
.



Relevant Pages

  • Re: Are re-entrant functions not such a big deal?
    ... chaos will result when we try to unfix the tail node after the ... The first definition doesn't lend itself very well to optimization ... eliminate .FORE, the parts you show between BEGIN and WHILE, and the ... the compilation of .FORE itself. ...
    (comp.lang.forth)
  • Re: Python becoming less Lisp-like
    ... > like in Scheme. ... I am sorry to pick nits, but turning tail call optimization off would ... specify a zillion other optional features. ...
    (comp.lang.lisp)
  • Re: Memory requirements
    ... > The above expression should be covered by tail call optimization, ... > optimization for call/cc. ... R5RS gives a formal definition of tail contexts in section 3.5. ... the loop for call/cc need not be optimized. ...
    (comp.lang.scheme)
  • Re: tail-rec decorator, well still blows the stack...
    ... # This program shows off a python decorator( ... # which implements tail call optimization. ... This function decorates a function with tail call ... It does this by throwing an exception ...
    (comp.lang.python)
  • Re: multi-threading in Forth?
    ... manipulation is more useful than tail call optimization. ... but IME code that uses the ... Forth compilers - instead of searching "where is it this time?". ...
    (comp.lang.forth)