是否可以将函数指针获取到具有前缀的函数起初我以为c函数的名字在编译过程中丢失了然后,dlsym返回指向指定名称的函数的指针。
所以如果有办法的话:
void * handle = dlopen(0, RTLD_NOW|RTLD_GLOBAL);
*(void **)(&fptr);
while(fptr = dlsym(handle, "prefix*")) {
fptr(args);
}
最佳答案
为什么不这样做呢:
#include <stdio.h>
void funcA(int n) { printf("funcA: %d\n", n); }
void funcB(int n) { printf("funcB: %d\n", n); }
void funcC(int n) { printf("funcC: %d\n", n); }
void (*funcs[3]) (int n) = {
funcA,
funcB,
funcC
};
int main() {
int i;
for (i = 0; i < sizeof funcs / sizeof *funcs; ++i)
funcs[i](i);
return 0;
}
关于c - 在C中获取所有带前缀的函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24043843/