Type of function returning function.
Will Crowder
will at kfw.COM
Thu Jul 12 01:54:51 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 *)
>
>Example:
>
>int foo(buff)
>char *buff;
>{
> return atoi(buff);
>}
>
>TYPE bar()
>{
> return foo;
>}
>
>I would have thought that it would be something like
>int ((*)()), but gcc doesn't agree. Help...
>
>--
>Roger Fujii - Media Cybernetics Phone: (301)495-3305
>Internet: rmf%media at uunet.uu.net UUCP: {uunet,hqda-ai}!media!rmf
These are a pain.
int (*bar())();
ought to do it for you though. I'm sure it's been discussed here before,
but there exists something called the "right-left" rule for deciphering
and creating C declarations, and it comes in quite handy. If you haven't
heard of it, ask your local C guru or e-mail me, and I'll be happy to
explain it.
OBTW, if you want a full prototype, based on what you have above, it would
be:
int (*bar(void))(char *);
and the typedef would be:
typedef int (*TYPE(void))(char *);
or
typedef int (*TYPE())();
without the prototypes.
Hope this helps,
Will
More information about the Comp.lang.c
mailing list