If I want to define a pointer variable p to point to the function foo() defined as below, what should be the exact type of p?
int *foo(void *arg)
{
...
}
It should be
typedef int *(*funtion_foo_type)(void *);
typedef for the function signature, that is like the function but with typedef before, e.g. typedef int*foo_type(void*); then using a pointer to that type, i.e. foo_type* funptr; is even more readabletypedef is not an operator. Syntactically it is a storage-class specifier. A typedefed name is an alias for the actual type.typedef, I meant whole string. Tried to avoid confusion, made more confusion (:To make it more easy you could for the function declaration
int *foo(void *arg);
define an alias named as for example Tfoo that looks the same way as the function declaration itself
typedef int *Tfoo(void *);
After that to declare a function pointer to the function is very easy. Just write
Tfoo *foo_ptr = foo;
Otherwise you could write
typedef int * (* TFoo_ptr )(void *);
Tfoo_ptr foo_ptr = foo;
Or you could write a declaration of the function pointer directly without using the typedef/
int * (* foo_ptr )(void *) = foo;