user3032207
user3032207

Reputation: 1

C programming - compiler tells me I am dereferencing an incomplete type

The structure of code is I have a struct "entry", which is stored within a circular list "bucket", which is stored within a hash table. An "entry" has two fields (a and b), and when I search for field a and return field b, I'm trying to do it in the following way:

ht_lookup(d.dict->items[bucket],field_a)

I have searched on this and the solution seems to be to include the header file which defines the bucket, but I have included the header file which defines bucket, i.e. the circular list, so I don't understand how the type is incomplete. Is there something I can do with the code as it is to render the type complete?

I am at my wit's end, any help really appreciated.

struct dictionary
{
  ht *   dict;
} d;

struct entry
{
  char   word[MAX_WORD_SIZE];
  char   desc[MAX_DESC_SIZE];
};

This is after

`#include "ht.h"`

Which is where the hash table is defined, which is what each bucket is:

ht * new_ht(int max, hashfun h1, getkeyfun getkey)
{
int i;
ht * t = (ht*)malloc(sizeof(ht));
t->items = (clist**)malloc(max * sizeof(clist*));
t->size = 0;
t->h1 = h1;
t->getkey = getkey;
t->max = max;
for (i=0; i<max; i++)
    t->items[i] = new_clist();
return t;
}

gcc is outputting this error:

error: dereferencing pointer to incomplete type

Upvotes: 0

Views: 73

Answers (1)

lvella
lvella

Reputation: 13413

d.dict is a pointer to something, the definition of this something is missing to the compiler. d is of type of some struct that contains a dict member, that is a pointer to some (possibly) other struct. The definition of this other struct is missing in the compilation unit.

Upvotes: 1

Related Questions