I have a chained hash table with the following structure:
typedef struct{
char* phrase;
struct phrase_struct* next;
}phrase_struct;
My immediate concern about this structure was that the pointer actually referred to a typedef that may not have been defined yet .. but it compiled so I figured it was valid syntax. I have several functions that either allocate memory and manipulate the pointer next
that points to the next node.
Consider pointers of the following type and an automatically allocated struct:
phrase_struct* ptr1
phrase_struct* ptr2
phrase_struct test_s;
If I did the following assignments:
ptr1 = &test_s
ptr2 = test_s.next;
<- this pointer would be set to NULL elsewhere in the code
I would continually get error complaining about incompatible assignments of the type:
'=' : incompatible types - from 'phrase_struct *' to 'phrase_struct *'
And then it hit me .. I recalled having previously read something regarding namespaces of typedef and actual structure names being independent.
typedef struct test{
char* phrase;
struct test* next;
}phrase_struct;
Changing the structure definition to this fixed all the warnings.
Can someone explain this?