Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!ames!lll-lcc!pyramid!thirdi!peter From: peter@thirdi.UUCP (Peter Rowell) Newsgroups: comp.lang.c Subject: Re: Mutually recursive functions in C Message-ID: <447@thirdi.UUCP> Date: 12 Feb 89 20:24:56 GMT References: <34823@tut.cis.ohio-state.edu> Reply-To: peter@thirdi.UUCP (Peter Rowell) Distribution: usa Organization: Third Eye Software, Menlo Park, CA Lines: 60 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? I think the best question for C is: "What does C *not* allow?" The answer is "not much". This is a shorter answer than for the opposite question. In this particular case, the answer is yes, C "allows" mutually recursive functions because C really doesn't give a damn about how who calls what from where with what. If the routines return anything other than "int" (or if you are using ANSI C with prototypes), you will need to place an extern declaration in the front of the file so that the compiler doesn't bitch about "Redeclaration of procedure Foo", but other than that - anything goes! How about a pair of routines that further abuse the often abused computation of a factorial? (And, No - I didn't bother trying to run/debug this gibberish!) (And, Yes - I know they are the same routine, but how often do you get to write garbage like this and actually get to pretend you're making sense?!) extern int fact_odd(); int fact_even(x) int x; { if (x <= 1) return(1); return(x * ((x & 1) ? fact_odd(x-1) : fact_even(x-1))); } int fact_odd(x) int x; { if (x <= 1) return(1); return(x * ((x & 1) ? fact_odd(x-1) : fact_even(x-1))); } Someone on the net a couple of years ago made the following apt comparison: Pascal is like the round nose scissors you had in kindergarten - you can do a number of things, but you have to really *try* to cut yourself. C is like a pack of two-edged razor blades - capable of precisely doing a large number of things ... and if you are not very careful you will end up bleeding to death on the machine room floor. Hmmmmm..... I wonder, is that why hackers like C? :-) ---------------------------------------------------------------------- Peter Rowell "C - the Sweeny Todd of languages." Third Eye Software, Inc. (415) 321-0967 Menlo Park, CA 94025 peter@thirdi.UUCP