Mutually recursive functions in C

Brad Brown bradb at ai.toronto.edu
Mon Feb 13 04:21:04 AEST 1989


In article <34823 at tut.cis.ohio-state.edu> william at 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?
>
>Jim Williamson


Sure, C will let you do anything...  :-)

Try the following, with appropriate adjustments for your argument types:

>-------------------------------------

:
:

int func1( int argument )
{
	/*  Remember to have a forward reference for the second function  */
	/*  You might have to modify the syntax of this -- my compiler    */
	/*  accepts it, but a minimal declaration is just "int func2()"   */
	/*  with no extern -- it works but does not give you protection   */
	/*  against type mismatches in the argument to func2().           */
	extern int func2( int );

	/*  Do stuff  */
	:
	:
	func2( stuff );
	:
	:
}

int func2( int argument )
{
	/*  Don't need a forward reference for func1 here  */

	/*  Do stuff  */
	:
	:
	func1( stuff );
	:
	:
}

>-------------------------------------

That's it!

					(-:  Brad Brown  :-)
					bradb at ai.toronto.edu




More information about the Comp.lang.c mailing list