Hi everyone, I'm currently working on a school assignment and came up with this error saying 'list_t has no member named head' but when I actually look at list.h and list.c (my code accessing list is in a separate file), head is in list.c. What did I do wrong?

list.c
typedef struct node node_t;

struct list {
    node_t *head;
};

struct node {
    void *data;
    node_t *next;
};



list.h
typedef struct list list_t;


flange.c
vector_t start;
vector_t end;
list_t *params = datacons_params(shape);
list_t *tempList = tuple_val((value_t *)list_nth(params, 0));
start.x = tempList->head->data;
start.x = tempList->head->next->data;

and tuple_val returns (list_t *val)

You should struct/class declarations in your header file (.h)

list.h

struct list {
    node_t* head;
};

typedef struct list list_t;

Because when you rename the structure list to list_t but nowhere was struct list defined before that line.

I think I understand what you mean but both list.c and list.h are given and I don't think I'm supposed to change the code in them. Also, the code given in list.c had no problem in accessing head.

some code in list.c
list_t *list_empty(void)
{
  list_t *l;

  l = (list_t *)util_malloc(sizeof(list_t));
  l->head = NULL;

  return l;
}

Because when you rename the structure list to list_t but nowhere was struct list defined before that line.

That's not a problem. You can use an incomplete type as the alias in a typedef, provided there's no instantiation of the typedef that would require the alias to be complete until there's a definition for the alias. Since the only use of list_t prior to definition of struct list is through pointers to list_t, all is well.

My guess would be that list.h is included, but list.c either isn't in the build or is being linked in the wrong order. So flange.c sees the definition of list_t, but not the definition of struct list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.