Re: C functions
Re: C functions
- Subject: Re: C functions
- From: Charles Srstka <email@hidden>
- Date: Thu, 17 Oct 2013 22:49:16 -0500
On Oct 17, 2013, at 10:40 PM, Maxthon Chan <email@hidden> wrote:
> You actually can, by using dlsym(3) to resolve the symbol, cast it to the appropriate function pointer and call it.
>
> For example:
>
> int (*myfunc)(int, int) = dlsym(RTLD_DEFAULT, myfunc_name);
> if (myfunc)
> printf(“%d”, myfunc(2, 3));
> else
> fprintf(stderr, “error: cannot resolve symbol: %s”, myfunc_name);
>
> This works on all POSIX operating systems.
You shouldn't rely on dlsym() working in production code. If the binary is stripped (as it is by default for release builds, I believe), it won't work.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden