- 论坛徽章:
- 0
|
在man dlopen中看到了个这样的*(void **)(&cosine),该如何理解呢?
Load the math library, and print the cosine of 2.0:
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen ("libm.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}
dlerror(); /* Clear any existing error */
*(void **) (&cosine) = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\n", error);
exit(1);
}
printf ("%f\n", (*cosine)(2.0));
dlclose(handle);
return 0;
}
不理解为什么不直接cosine = dlsym(handle, "cos");
dlsym的原型: void *dlsym(void *handle, const char *symbol);
[ 本帖最后由 hahasasa 于 2008-7-15 10:43 编辑 ] |
|