0

我有一个函数,我想将它作为参数传递给另一个函数(我们称之为 funX)。这是 funX 原型:

void funX(const unsigned char *, unsigned char *, size_t, const somestruct *, unsigned char *, const int);

和我的调用 funX 的函数(我们称之为 funY):

unsigned char * funY(unsigned char *in, unsigned char *out, size_t len, unsigned char *i, void *k, int ed, void (*f)(unsigned char *, unsigned char *, size_t, const void *, unsigned char *, const int))
{
    f(in, out, len, k, i, ed);
}

但是我在编译时有一些警告:

test.c: In function ‘main’:
test.c:70:5: warning: passing argument 7 of ‘funY’ from incompatible pointer type [enabled by default]
test.c:11:17: note: expected ‘void (*)(unsigned char *, unsigned char *, size_t,  const void *, unsigned char *, const int)’ but argument is of type ‘void (*)(const unsigned char *, unsigned char *, size_t,  const struct somestruct *, unsigned char *, const int)’
4

3 回答 3

3

查看警告并比较原型

预期的:-

void (*)(unsigned char *,       unsigned char *, size_t,  const void *,              unsigned char *, const int)

假如 :-

void (*)(const unsigned char *, unsigned char *, size_t,  const struct somestruct *, unsigned char *, const int)
于 2013-09-01T18:39:19.213 回答
2

您是否阅读了整个错误消息?

您在两个函数的签名中有一些const- 和其他类型不匹配(例如,指向 -struct而不是 的指针void *等)。只有当它们的签名完全匹配时,函数类型才兼容。

于 2013-09-01T18:37:33.300 回答
1

您的签名似乎有所不同。见下文。

void funX(const unsigned char *, unsigned char *, size_t, --> const somestruct * <--, unsigned char *, const int);

void (*f)(unsigned char *, unsigned char *, size_t, --> const void * <--, unsigned char *, const int)
于 2013-09-01T18:38:45.693 回答