Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!security!genrad!decvax!ittvax!bunker!bunkerb!garys From: garys@bunkerb.UUCP (Gary Samuelson) Newsgroups: net.unix,net.lang.c Subject: Re: functions returning pointers to functions Message-ID: <268@bunkerb.UUCP> Date: Wed, 14-Dec-83 15:17:19 EST Article-I.D.: bunkerb.268 Posted: Wed Dec 14 15:17:19 1983 Date-Received: Sat, 17-Dec-83 00:54:21 EST Lines: 53 In reply to Steve Summit, who wanted a function returning a pointer to a function returning an integer: I tried to write this reply in the same style as your request, but I guess I don't speak King James English well enough. Will Today's English suffice :-) ? Using a typedef divides the declaration into bite-sized pieces, which the compiler can swallow. The following program, which I have compiled and run on our VAX (4.1BSD), contains such a function. Simply tear along the dotted line. Gary Samuelson decvax!ittvax!bunker!bunkerb!garys ------------------------------------------------- /* * a couple of functions which return integers */ int g( x ) int x; { return( x + x ); } int h( x ) int x; { return( x * x ); } /* * A function which returns a pointer to a function * which returns an integer. */ typedef int (*ifp)() ; ifp f( a ) int a; { if( a == 0 ) return( g ); else return( h ); } main() { printf( "%d\n", ((*f)( 0 )) ( 4 ) ); printf( "%d\n", ((*f)( 1 )) ( 4 ) ); }