Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown type name C

Tags:

c

I know that things have to be defined before they are used, but I am getting an "unknown type name error."

This is my Node definition:

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];
like image 254
J. Jones Avatar asked Dec 06 '16 18:12

J. Jones


2 Answers

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

typedef struct Node Node;

Alternatively, you could use struct Node in your declaration:

struct Node* hashtable[HashArraySize];
like image 165
Sergey Kalinichenko Avatar answered Nov 12 '22 21:11

Sergey Kalinichenko


Change Node* hashtable[HashArraySize]; to struct Node* hashtable[HashArraySize];

or

typedef struct Node  {
    position* p;
    struct Node* next;
    struct Node* prev;
} Node;
like image 43
Renato Medeiros Avatar answered Nov 12 '22 23:11

Renato Medeiros