Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Called object is not a function or a 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 is going on here? Haven't I declared and used the function pointer f in a correct way?

like image 878
pythonic Avatar asked Dec 01 '25 05:12

pythonic


1 Answers

getpidType is already a pointer, so drop the *:

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

(Even better, drop the explicit cast as well:

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

Since dlsym returns void* and void* is implicitly convertible to any other pointer type, the cast is not needed. It may even hide bugs.)

like image 114
Fred Foo Avatar answered Dec 03 '25 20:12

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!