2015-07-28 94 views
1

我的头定义了以下代码:Ç - 前函数参数预期的声明符或“...”

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}; 
+0

你怎么申报'enroll'和'change'? –

+1

删除了我的答案,因为虽然*可能*在某处忘记了分号,但没有人能真正告诉这一小段代码。请显示一个完整的可证实的问题示例。 –

+0

@MichaelWalz和Felix,我已经更新了我的问题。 – user3815726

回答

1

要传递到你的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; 
} 
+0

删除了我的评论,谢谢你的示例代码。 – user3815726

+0

在我的情况下,ClientAlloc将是要执行的函数。我在这里没有主要。你能修改示例代码吗? – user3815726

+0

@ user3815726由什么执行?不是功能?将代码'ClientAlloc(登记,更改)'移到你需要的地方。 – LPs

1

这这里编译罚款:

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); 
} 
+0

在我的情况下,ClientAlloc将是要执行的功能。我在这里没有主要。你能修改示例代码吗? – user3815726

+0

@ user3815726为什么修改编译的代码并且工作正常?我不确定我明白。 –

+0

你是对的,对不起,我误解了代码。 – user3815726