Marshall Tigerus
Marshall Tigerus

Reputation: 3764

expected expression before "hashLink"

I'm getting an error I cannot figure out. I'm trying to define an instance of a struct. I do this several times in the code, and I get the same error every time. I am unsure what I am doing wrong.

Struct Definition:

 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;

Call in the code (one example):

hashLink *temp = malloc(sizeof hashLink);
hashLink *temp2 = malloc(sizeof hashLink);

precise error I get is:

 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'|

Upvotes: 1

Views: 141

Answers (1)

zentrunix
zentrunix

Reputation: 2266

sizeof hashLink ---> sizeof(hashLink)

When used with types, the operator sizeof requires parentheses.

Upvotes: 3

Related Questions