Recursive function declarations

David Keppel pardo at june.cs.washington.edu
Sat Jul 16 06:28:17 AEST 1988


In article <323 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
>[ Function returning pointer to function returning pointer to fun...]
>[ How do I declare it? ]

To the best of my knowledge (correct me, please), you can't  You
need to declare it as returning a most-general pointer (void* if you
have one) and then cast it when you call:


    #include <stdio.h>

    /* a function returning a void* cast pointer to a function */
	void*
    foo()
    {
	static int i = 10;
	return  i-- ? (void*)foo : NULL;
    }

    main()
    {
	typedef void *(*fptr)();	/* ptr to func ret ptr to void */
	fptr func = foo;

	while ( func = (fptr)(*func)() ) {	/*VALUSED*/
	    printf( "looping\n" );
	}
	exit(0);
    }

(Gcc compiles and runs this on a VAX.  Whether it's correct, I dunno.)

	;-D on  ( Better chemistry through living )  Pardo



More information about the Comp.lang.c mailing list