Type of function returning function.

diamond@tkovoa diamond at tkou02.enet.dec.com
Wed Jul 11 14:27:35 AEST 1990


In article <1990Jul10.024205.17382 at media.uucp> rmf at media.uucp (Roger Fujii) writes:
>So, just how does one type a function returning a pointer to a function?
>(other than the obvious void *)

The obvious (void *) does not work, except by accident on some machines
(and, depending on the machine, some segmentation models).  (void *) only
works for pointers to data.

For your example below,

typedef int (*TYPE)(char *);
>int foo(buff) char *buff; { return atoi(buff); }
>TYPE bar() { return foo; }

Alternatively,

int (*bar())(char *) { return foo; }

I recommend the typedef.
-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.



More information about the Comp.lang.c mailing list