Unknown type name C

I know that things must be defined before they can be used, but I get an “unknown type name error”.

This is my definition of Node :

 struct Node { position* p; struct Node* next; struct Node* prev; }; 

This is my declaration (on line 96):

 Node* hashtable[HashArraySize]; 

I get this error message:

 P1.c:96:1: error: unknown type name 'Node' Node* hashtable[HashArraySize]; 
+5
source share
2 answers

Unlike C ++, which treats struct tags as new type names, C requires an explicit typedef if you want to use Node without a struct :

 typedef struct Node Node; 

Alternatively, you can use struct Node in your declaration:

 struct Node* hashtable[HashArraySize]; 
+9
source

Change the Node* hashtable[HashArraySize]; on struct Node* hashtable[HashArraySize];

or

 typedef struct Node { position* p; struct Node* next; struct Node* prev; } Node; 
+6
source

Source: https://habr.com/ru/post/1260895/


All Articles