Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Tail recursion in C Message-ID: <10530@smoke.BRL.MIL> Date: 15 Jul 89 04:52:51 GMT References: <33133@apple.Apple.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 13 In article <33133@apple.Apple.COM> landon@Apple.COM (Landon Dyer) writes: >At first glance, 'f()' is a tail-recursive function that recurses 'n+1' >times. But we're in trouble, because third parties (the global 'gLinkList' >in this case) have pointers to locals that are contained in the control >stack. C allows general recursion, not just tail recursion. Of course you're constrained in that you can't legally use variables once their lifetime has expired; however in your example all autos in the function nest would still be alive for the n<0 branch of the innermost call. What you DO have to watch out for is not relying on the auto storage mechanism to provide storage outside the dynamic scoping inherent in the use of a stack discipline. That's what the heap (malloc()) is for.