C-预期的声明说明符或‘’;函数参数之前
我的标题定义了以下代码:C-预期的声明说明符或‘’;函数参数之前,c,typedef,C,Typedef,我的标题定义了以下代码: 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);
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’
这里有什么我可能错过的吗
对于EnrollT
和ChangeT
,我在我的代码中声明:
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};
您正在传递给您的
Enroll
和Change
功能的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;
}
#包括
#包括
类型定义uint8注册(uint16测试1、uint16测试2);
类型定义无效变更(uint64邮政编码1、uint8邮政编码2);
结构ClusterT*ClientAlloc(注册*p,变更*q)
{
返回NULL;
}
uint8注册(uint16测试1、uint16测试2)
{
返回0;
}
无效更改(uint64邮政编码1、uint8邮政编码2)
{
}
内部主(空){
ClientAlloc(注册、更改);
返回0;
}
这里编译得很好:
typedef uint8_t EnrollT(uint16_t test1, uint16_t test2);
typedef void ChangeT(uint64_t post1, uint8_t post2);
struct ClusterT * ClientAlloc(EnrollT *, ChangeT *);
struct ClusterT * ClientAlloc(EnrollT *x, ChangeT *y)
{
(*x)(22,33);
return NULL;
}
unsigned char enrollfunc(uint16_t test1, uint16_t test2)
{
return 123;
}
void main()
{
EnrollT *x = enrollfunc;
ChangeT *y = NULL;
ClientAlloc(x, y);
}
您是如何声明
enroll
和change
的?删除了我的答案,因为尽管您可能在某处忘了一个分号,但没有人能用这一点点代码真正分辨出来。请给出一个完整的可验证的问题示例。@MichaelWalz和Felix,我已经更新了我的问题。我根据问题中给出的代码片段制作了一个示例(尽管我在每个函数实现后删除了不必要的尾部;
),结果是-没有编译错误(MSVC)。在我的情况下,ClientAlloc将是要执行的函数。我这里没有主菜。请修改示例代码好吗?@user3815726由什么执行?其他功能?移动代码ClientAlloc(注册,更改)
您需要它的地方。我的意思是ClientAlloc会喜欢我的案例中的主要功能。对不起,我有点困惑structclustert*ClientAlloc(EnrollT*p,ChangeT*q){..}
是函数。如果你想用它来代替main,你不能。否则我就不明白了。在我的例子中,ClientAlloc将是要执行的函数。我这里没有主菜。请修改示例代码好吗?@user3815726为什么要修改编译良好的代码?我不太明白。