Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!agate!shelby!neon!Gang-of-Four!dkeisen From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.lang.c Subject: Re: Type of function returning function. Message-ID: <1990Jul11.165805.14866@Neon.Stanford.EDU> Date: 11 Jul 90 16:58:05 GMT References: <1990Jul10.024205.17382@media.uucp> Sender: news@Neon.Stanford.EDU (USENET News System) Organization: Sequoia Peripherals Lines: 59 In article <1990Jul10.024205.17382@media.uucp> rmf@media.uucp (Roger Fujii) writes: >So, just how does one type a function returning a pointer to a function? >(other than the obvious void *) > >Example: > >int foo(buff) >char *buff; >{ > return atoi(buff); >} > >TYPE bar() >{ > return foo; >} > Those who suggested it would be clearer using a typedef are probably right, but it's no big deal doing it directly either. As always, declare things the same way they will be used. In an expression, bar () will be a pointer to a function. To use this, you would dereference the pointer --- *bar () ---- and then use it for a function call --- (*bar ()) () --- which returns an int. int (*bar ()) () { return foo; } should work fine. I've only used Classic C, but I believe the way it is done in ANSI C is as follows: int foo (char *buf) { return atoi (buf); } int (*bar (void)) (char *) { return foo; } where the type of bar is changed to function taking no arguments returning a pointer to a function taking a char * and returning an int. -- Dave Eisen Home: (415) 323-9757 dkeisen@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043