I have the following code.
typedef pid_t (*getpidType)(void);
pid_t getpid(void)
{
printf("Hello, getpid!\n");
getpidType* f = (getpidType*)dlsym(RTLD_NEXT, "getpid");
return f(); // <-- Problem here
}
The compiler complains that called object ‘f’ is not a function. What is going on here? Haven’t I declared and used the function pointer f in a correct way?
getpidTypeis already a pointer, so drop the*:(Even better, drop the explicit cast as well:
Since
dlsymreturnsvoid*andvoid*is implicitly convertible to any other pointer type, the cast is not needed. It may even hide bugs.)