Article View: comp.lang.misc
Article #4436Re: C compilers which optimize tail calls (was: GOTO controversy)
From: Kelly Hall
Date: Sun, 07 Apr 1996 00:18
Date: Sun, 07 Apr 1996 00:18
29 lines
2242 bytes
2242 bytes
>>>>> "Rickard" == Rickard Westman <ricwe@ida.liu.se> writes:
Rickard> The sad truth is that this program, compiled with GCC
Rickard> 2.7.0 (-O3), blows the stack when tested with a number
Rickard> large enough. Tail calls within a single function seems
Rickard> to be optimized, though, but this limitation is really
Rickard> too restrictive for people who want to program in a
Rickard> functional style (or translate functional programs to C).
Hmm - I never bothered to try mutually (tail)recursive functions. I'm
not really surprised that Gcc doesn't handle the calls well.
Rickard> On the other hand, Suns unbundled C compiler (v3.0.1)
Rickard> seems to handle this example well, as well as mutual
Rickard> recursion between different compilation units. The DEC
Rickard> OSF/1 compiler (v3.11 on an Alpha) also does OK, but only
Rickard> within a single compilation unit. More data points?
I tried this test with both the HP C compiler (the development
compiler, with most patches) and GCC 2.6.3. Both seemed to run out of
gas at about the same rate. So I think that HP (and FSF) might stand
to improve their handling of mutual (tail) recursion.
Rickard> All in all, I don't think it's wise to assume that tail
Rickard> call optimization is done by the typical C compiler.
I stand corrected. So why haven't more C compiler folks added this
useful optimization?
Kelly
Technical Details
Message-ID:
<ouivfcnaxq.fsf@lynx.cs.byu.edu>Path:
arc1-ca.pugleaf.net!hamblin.math.byu.edu!usenetReferences:
<314FB5F5.259B@simi.is> <AD87DB279668D9F74@mcdiala15.it.luc.edu> <828549619snz@genesis.demon.co.uk> <oun34tm3c7.fsf@lynx.cs.byu.edu> <DpCv8o.9Mw@ida.liu.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!hamblin.math.byu.edu!usenet From: hall@cs.byu.edu (Kelly Hall) Newsgroups: comp.lang.misc,comp.lang.c,gnu.gcc Subject: Re: C compilers which optimize tail calls (was: GOTO controversy) Followup-To: comp.lang.c Date: 06 Apr 1996 18:18:41 -0600 Organization: Computer Science Dept. BYU Sender: hall@lynx.cs.byu.edu Message-ID: <ouivfcnaxq.fsf@lynx.cs.byu.edu> References: <314FB5F5.259B@simi.is> <AD87DB279668D9F74@mcdiala15.it.luc.edu> <828549619snz@genesis.demon.co.uk> <oun34tm3c7.fsf@lynx.cs.byu.edu> <DpCv8o.9Mw@ida.liu.se> NNTP-Posting-Host: lynx.cs.byu.edu Mime-Version: 1.0 (generated by tm-edit 7.46) Content-Type: text/plain; charset=US-ASCII In-reply-to: ricwe@ida.liu.se's message of Thu, 4 Apr 1996 20:50:47 GMT X-Newsreader: Gnus v5.0.15