C - 在函数参数之前的预期声明说明符或'...'

时间:2015-07-28 08:36:36

标签: 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);

然而,当我编译源代码时,会弹出错误。

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

2 个答案:

答案 0 :(得分:1)

您要转到ClientAllocEnroll函数的Change个函数地址

然后你的

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

答案 1 :(得分: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);
}