<分区>
假设有人想创建一个可以容纳多个函数指针和不同类型的数组..他会怎么做呢?也许一个 void 指针数组可以工作?......事实证明,不,因为为了使用存储在 void 指针中的函数,你必须将它们(void 指针)转换/转换回函数指针和...
"A conversion between a function pointer and a void pointer is not possible. void* was never a generic pointer type for function pointers, only for object pointers. They are not compatible types.
[...] you can cast between void* and a function pointer, but what will happen is undefined behavior. You will be relying on system-specific non-standard extensions."
-@Lundin (here)
相反...
Slightly better would be to use a function pointer type such as void (*)(void) as the generic pointer. You can convert to/from different function pointers, what will happen is compiler-specific (implementation-defined behavior). That is, the code will still be non-portable, but at least you don't risk a program crash from invoking undefined behavior.
-@Lundin (here)
也就是说,从一个函数指针转换为另一个函数指针到底意味着什么?
谁能解释一下。也许有一个例子。