gpt4 book ai didi

C - 函数参数前的预期声明说明符或 ‘...’

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

我的标题定义了以下代码:

typedef uint8_t EnrollT(uint16_t test1, uint16_t test2);
typedef void ChangeT(uint64_t post1, uint8_t post2);

struct ClusterT * ClientAlloc(EnrollT *, ChangeT *);

我已经实现了这两个函数并将它们传递给我的 c 文件中的 ClientAlloc(),如下所示:

ClientAlloc(Enroll, Change);

但是,当我编译源代码时,会弹出错误。

expected declaration specifiers or ‘...’ before ‘enroll’
expected declaration specifiers or ‘...’ before ‘change’

这里有什么我可能会遗漏的吗?

对于 EnrollTChangeT,我在我的代码中声明:

uint8_t Enroll(uint16_t test1, uint16_t test2){...};
void Change(uint64_t post1, uint8_t post2){...};

对于 ClienAlloc:

struct ClusterT * ClientAlloc(Enroll, Change){... return something};

最佳答案

您正在将 EnrollChange 函数的地址传递给 ClientAlloc

然后是你的

struct ClusterT * ClientAlloc(Enroll, Change){... return something}

必须是

struct ClusterT *ClientAlloc(EnrollT *p, ChangeT *q){... return something}

示例代码是:

#include <stdint.h>
#include <stdlib.h>

typedef uint8_t EnrollT(uint16_t test1, uint16_t test2);
typedef void ChangeT(uint64_t post1, uint8_t post2);

struct ClusterT *ClientAlloc(EnrollT *p, ChangeT *q)
{
return NULL;
}

uint8_t enroll(uint16_t test1, uint16_t test2)
{
return 0;
}

void change(uint64_t post1, uint8_t post2)
{

}

int main(void) {

ClientAlloc(enroll, change);

return 0;
}

关于C - 函数参数前的预期声明说明符或 ‘...’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31671245/

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