From: Martin Str|mberg Subject: Re: Recursions and Static declarations....?Is this wrong... Newsgroups: comp.os.msdos.djgpp,comp.lang.c References: <5a91d0ef DOT 0207181004 DOT 49e67056 AT posting DOT google DOT com> User-Agent: tin/1.4.4-20000803 ("Vet for the Insane") (UNIX) (NetBSD/1.5_BETA (alpha)) Message-ID: <1027079317.518196@queeg.ludd.luth.se> Cache-Post-Path: queeg.ludd.luth.se!unknown AT speedy DOT ludd DOT luth DOT se X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) Date: 19 Jul 2002 11:48:37 GMT Lines: 35 NNTP-Posting-Date: 19 Jul 2002 11:48:37 GMT NNTP-Posting-Host: queeg.ludd.luth.se X-Trace: 1027079317 news.luth.se 466 130.240.16.109 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In comp.os.msdos.djgpp Hans-Bernhard Broeker wrote: : In comp.os.msdos.djgpp Pradeepto K Bhattacharya wrote: :> Can I not use Static with recursions... : No, you can't. At least not sensibly, in the way you did it. You Why not? (Of course in this case it's strange.) But in general is there anything in C that states that it's broken having (and refering and assigning to) static variables in a recursive function? Say I have this function: void f(int i) { static depth = 0; depth++; printf("f: depth = %d.\n", depth); if( 0 < i ) { f(i-1); } depth--; } Wouldn't f(3) give a printout of 1, 2, 3, 4? Right, MartinS