The called object is not a function or function pointer

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's going on here? Didn't I declare and use the function pointer f ?

+3
source share
1 answer

getpidTypeis already a pointer, so release *:

getpidType f = (getpidType)dlsym(RTLD_NEXT, "getpid");

(Better yet, also remove the explicit cast:

getpidType f = dlsym(RTLD_NEXT, "getpid");

Since it dlsymreturns void*, but is void*implicitly converted to any other type of pointer, casting is not required. This may even hide errors.)

+9
source

All Articles