S
signuts
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
/* non standard header */
int main(int argc, char **argv) {
void *libtest;
void (*p)(void *,...);
libtest = dlopen("libtest.so", RTLD_LAZY);
if (libtest == NULL) {
printf("%s\n", dlerror());
exit(EXIT_FAILURE);
}
p = dlsym(libtest, "test2");
if (p == NULL) {
printf("%s\n", dlerror());
exit(EXIT_FAILURE);
}
(*p)(NULL, "two");
dlclose(libtest);
exit(EXIT_SUCCESS);
}
This is the code snip I am using to demonstrate the use of function
pointers. I would like to know the difference between declaring a function
pointer like 'void (*p)(void *, void *)' when you could easily have a
"generic" one declared like the one displayed in this example.
I have two functions, test and test2 in libtest.so. test has no arguments
and test2 has two strings, I found I can call the functions using this
"magic" pointer.
I am hoping for a response back, thanks.
- Sig
#include <stdlib.h>
#include <dlfcn.h>
/* non standard header */
int main(int argc, char **argv) {
void *libtest;
void (*p)(void *,...);
libtest = dlopen("libtest.so", RTLD_LAZY);
if (libtest == NULL) {
printf("%s\n", dlerror());
exit(EXIT_FAILURE);
}
p = dlsym(libtest, "test2");
if (p == NULL) {
printf("%s\n", dlerror());
exit(EXIT_FAILURE);
}
(*p)(NULL, "two");
dlclose(libtest);
exit(EXIT_SUCCESS);
}
This is the code snip I am using to demonstrate the use of function
pointers. I would like to know the difference between declaring a function
pointer like 'void (*p)(void *, void *)' when you could easily have a
"generic" one declared like the one displayed in this example.
I have two functions, test and test2 in libtest.so. test has no arguments
and test2 has two strings, I found I can call the functions using this
"magic" pointer.
I am hoping for a response back, thanks.
- Sig