错误:在'{'令牌之前预期';',','或')'但是找不到?

时间:2015-11-02 14:35:50

标签: c function syntax-error

我有以下带有此功能的C代码:

alist* createalist(int length){   //error occurs here
    struct alist *alist2 = malloc(sizeof(struct alist));
    alist2->size = length;
    alist2->data = calloc(2, sizeof(void *));
    alist2->data[length] = NULL;
    return alist2;
}

这包含在.c文件中。我的.h文件声明如下:

alist* createalist(int length);

alist的typedef:

typedef struct alist {
  int current;
  int size;
  int increment_rate;
  void ** data;
} alist;

当然我把我的.h包含在我的.c中。这用于编译成功,但现在由于奇怪的原因我总是得到

error: expected ';', ',' or ')' before '{' token
开头时出现

错误。一切似乎都没问题。我不明白。

1 个答案:

答案 0 :(得分:3)

主要是猜测(通过查看sizeof(struct alist)的用法),但看起来像是

alist* createalist(int length){

应该是

struct alist* createalist(int length){...

编辑:

添加typedef struct部分后,我没有看到任何名为taille的结构成员,正在

中使用
alist2->taille = length;