指向函数指针的指针是否可以转换为 void 指针,反之亦然?
Is a pointer to function pointer convertible to a void pointer and vice versa?
void f(void);
void (*pf)(void) = f;
void *p = &pf;
(*(void (**)(void))p)();
我试图在 C 标准(草案)文档中找到有关此类转换的部分。但是我最后30分钟没能做到。
void指针和指向函数指针的指针之间的转换是如何定义的?
§6.3.2.3/p1:
A pointer to void
may be converted to or from a pointer to any
object type.
§6.2.5/p20:
A pointer type may be derived from a function type or an object
type, called the referenced type. [...] A pointer type is a
complete object type.
"pointer to function" 是一个对象类型,所以 "pointer to pointer to function" 是一个指向对象类型的指针,因此可以根据 §6.3.2.3/p1 与 "pointer to void
" 相互转换。
void f(void);
void (*pf)(void) = f;
void *p = &pf;
(*(void (**)(void))p)();
我试图在 C 标准(草案)文档中找到有关此类转换的部分。但是我最后30分钟没能做到。
void指针和指向函数指针的指针之间的转换是如何定义的?
§6.3.2.3/p1:
A pointer to
void
may be converted to or from a pointer to any object type.
§6.2.5/p20:
A pointer type may be derived from a function type or an object type, called the referenced type. [...] A pointer type is a complete object type.
"pointer to function" 是一个对象类型,所以 "pointer to pointer to function" 是一个指向对象类型的指针,因此可以根据 §6.3.2.3/p1 与 "pointer to void
" 相互转换。