简体   繁体   English

C / C ++将void *转换为int(*())(int,...);

[英]C/C++ casting void* to int ( * () ) (int,…);

How can I cast void* to int ( * () ) (int,...) ? 如何将void*int ( * () ) (int,...)

The void* is coming from a dlsym . void*来自dlsym This code isn't compiling: 此代码未编译:

typedef  int ( *PSYS () ) (int,...);
PSYS getf =  (PSYS) dlsym(lib, "function" );

If the symbol is a function pointer your typedef may be wrong. 如果符号是函数指针,则typedef可能是错误的。 Should be: 应该:

typedef int (*PSYS)(int, ...);

PSYS is the type of a function, not a pointer to a function. PSYS是函数的类型,而不是函数的指针。 You want 你要

typedef  int ( *PSYS () ) (int,...);
PSYS* getf =  (PSYS*) dlsym(lib, "function" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM