因此,我正在尝试解决此警告:nonstandard conversion between pointer to function and pointer to data我一直无法找出一种执行此操作的好方法。这些都是用c而不是c ++完成的。

目前,我有一个头文件:

typdef struct myConnection_s
{
    ...
    void*   Callback
} myConnection_t, *Connection


typdef HRESULT (*HttpHook)(Connection, char*);


在其他文件foo.c中,我有:

....
Connection myConnection;
...

HttpHook myHook = (HttpHook) myConnection->Callback;
...
return myHook(.....);


有没有解决此警告的好方法,而无需更改太多?如果不是,最好的重写方式是什么?

谢谢!

最佳答案

typedef struct myConnection_s
{
    /* ... */
    HttpHook Callback;
} myConnection_t, *Connection;


然后,您也可以稍后删除显式转换:

HttpHook myHook = myConnection->Callback;

if (myHook)
    myHook(/* ... */);


编辑:看起来您有订购问题...试试这个:

struct myConnection_s;

typedef HRESULT (*HttpHook)(struct myConnection_s *, char*);

typedef struct myConnection_s
{
    /* ... */
    HttpHook Callback;
} myConnection_t, *Connection;

关于c - 指针到函数指针错误之间的转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11161137/

10-12 03:09