declaring routines which return function pointers
Robert Viduya
robert at gitpyr.UUCP
Fri Dec 14 19:59:41 AEST 1984
> I have a routine which resembles the following:
>
> int (*f)();
> int fa(), fb();
>
> fa() {
> f = fb;
> return(f);
> }
>
> fb() {
> }
>
> The problem with the above is that lint complains about an illegal combin-
> ation of a pointer with an integer in the 'return' statement. I have tried
> various casts and function declarations to try to satisfy lint, but none of
> them have worked. Does anybody know what I should do to keep lint happy?
>
I played around with the code for about 30 minutes and the only thing I
accomplished was to make lint core dump twice. I only see one way of
doing it and C apparently doesn't support it. That way is to declare
fa() as:
int ((*fa)())();
This is broken down from:
int (*x)(); /* x is a pointer to a function returning an int */
int ((*y)())(); /* y is function returning a ptr to a func returning an int */
However, both lint and cc complain with 'function returns illegal type'.
May I suggest using casts?
robert
--
Robert Viduya
Office of Computing Services
Georgia Institute of Technology, Atlanta GA 30332
Phone: (404) 894-4669
...!{akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp}!gatech!gitpyr!robert
...!{rlgvax,sb1,uf-cgrl,unmvax,ut-sally}!gatech!gitpyr!robert
More information about the Comp.lang.c
mailing list