gpt4 book ai didi

c - 将函数指针传递给函数+函数参数

转载 作者:太空宇宙 更新时间:2023-11-04 05:41:18 25 4
gpt4 key购买 nike

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

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)’

最佳答案

查看警告并比较原型(prototype)

预期:-

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)

关于c - 将函数指针传递给函数+函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18561540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com