C指针增量有问题(我认为)

时间:2012-10-23 13:31:37

标签: c arrays pointers compilation

我想这是一个简单的错误但是在尝试编译我的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;

}

2 个答案:

答案 0 :(得分:6)

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

temp->currentTable[i].first = NULL;
temp->currentTable[i].bucketSize = 0;

答案 1 :(得分:0)

更改

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

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