我发现一个我搞不懂的错误。我试图定义一个结构的实例。我在代码中多次这样做,每次都会得到相同的错误。我不确定我做错了什么。
结构定义:

 struct hashLink {
      KeyType key; /*the key is what you use to look up a hashLink*/
      ValueType value; /*the value stored with the hashLink, a pointer to int in the case of concordance*/
      struct hashLink * next; /*notice how these are like linked list nodes*/
};
typedef struct hashLink hashLink;

调用代码(一个示例):
hashLink *temp = malloc(sizeof hashLink);
hashLink *temp2 = malloc(sizeof hashLink);

我得到的准确错误是:
 C:\Users\Marshall\C\CS261\hashMap.c||In function '_freeMap':|
 C:\Users\Marshall\C\CS261\hashMap.c|73|error: expected expression before 'hashLink'|
 C:\Users\Marshall\C\CS261\hashMap.c|74|error: expected expression before 'hashLink'|

最佳答案

sizeof hashLink-->sizeof(hashLink)
与类型一起使用时,运算符sizeof需要括号。

10-08 07:11