
a question on function returning a pointer to a function
What is wrong with the following piece of code (at compile-time)?
int a(int p);
int b(float p);
int (*which_funct(s))()
char *s;
{
if (!stricmp(s,"A"))
return(a);
if (!stricmp(s,"B"))
return(b);
Quote:
}
cc (on a Sun) doesn't complain at all. Neither does VAX-11 C. gcc
however gives an error about the last line (line 10) - incompatible
types. I've been told that it is because I didn't specify (in the
definition of which_funct()) what type of argument the function to
which I'm trying to return a pointer takes. But, what if I want to
return functions which take different arguments, like in the above
example? I want which_funct() to return a pointer to either function
A, which takes an int, or function B, which takes a float. What should
Mike Levin