Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ukma!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Mutually recursive functions in C Message-ID: <8905@alice.UUCP> Date: 12 Feb 89 15:20:46 GMT References: <34823@tut.cis.ohio-state.edu> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 56 In article <34823@tut.cis.ohio-state.edu>, william@cis.ohio-state.edu (James H. Williamson) writes: > Does C allow mutually recursive functions & if so > what are the declaration mechanisms & could somebody > give an example? Here's a factorial function needlessly written as a pair of mutually recursive functions: In C Classic: int fact(); /* not really necessary */ int tcaf(); int fact(n) int n; { if (n <= 0) return 1; else return n * tcaf (n-1); } int tcaf(n) int n; { if (n <= 0) return 1; else return n * fact (n-1); } In ANSI C: int fact(int); /* not really necessary */ int tcaf(int); int fact(int n) { if (n <= 0) return 1; else return n * tcaf (n-1); } int tcaf(int n) { if (n <= 0) return 1; else return n * fact (n-1); } -- --Andrew Koenig ark@europa.att.com