2

我猜这是一个非常简单的错误,但在尝试编译我的 C 代码时出现此错误:

error: expected identifier before '(' token

从这段代码中,我尝试为带有链表的哈希表设置结构以进行哈希冲突:

typedef struct bN {
    MEntry nestedEntry;
    struct bN *next;
} bucketNode;

typedef struct bL {
    bucketNode *first;
    int bucketSize;
} bucket;

struct mlist {
    bucket *currentTable;
};

而这段代码是我实际初始化链表的地方:

MList *ml_create(void){

    MList *temp;

    if (ml_verbose){
        fprintf(stderr, "mlist: creating mailing list\n");
    }
    if ((temp = (MList *)malloc(sizeof(MList))) != NULL){
        temp->currentTable = (bucket *)malloc(tableSize * sizeof(bucket));
        int i;
        for(i = 0; i < tableSize; i++){
            temp->(currentTable+i)->first = NULL; /**ERROR HERE*/
            temp->(currentTable+i)->bucketSize = 0; /**ERROR HERE*/
        }
    }
    return temp;

}
4

2 回答 2

6

您的语法已关闭。你的意思是:

temp->currentTable[i].first = NULL;
temp->currentTable[i].bucketSize = 0;
于 2012-10-23T13:35:36.190 回答
0

改变

temp->(currentTable+i)->first = NULL; 

成为

(temp->currentTable+i)->first = NULL; 
于 2012-10-23T13:35:40.120 回答