【发布时间】:2015-02-07 11:19:32
【问题描述】:
在 C99 中,除了检查每个单独的指针之外,还有更简单的方法来检查函数指针结构是否为 NULL?
我目前拥有的类似于以下内容:
typedef struct {
void* (*foo)(int a);
int (*bar)(int a, int b);
} funcs;
void *funcs_dll;
funcs_dll = dlopen("my_funcs_dll.so", RTLD_GLOBAL);
if (funcs_dll == NULL) {
THROW_ERROR;
}
funs.foo = dlsym(funcs_dll, "foo");
funcs.bar = dlsym(funcs_dll, "bar");
if (!funcs.foo || !funcs.bar) {
THROW_ERROR;
}
我要做的是减少第二个 if 检查,这样我就不需要检查每个单独的功能。任何建议都会有所帮助。
【问题讨论】:
-
看看this answer。
-
虽然代码不是正式定义好的行为,this example answers the question to 100%.
标签: c structure function-pointers c99