Search code examples
cincludeheader-files

Field has incomplete type even though included


One of my headers files queue.h has a structure with has a structure defined in another file, pathing.h. queue.h includes pathing.h, but not vice versa. The compiler, gcc, is telling me that the structure is an incomplete type. Multiple files in the project include both of them, but I made sure they include pathing.h first. I have look at various post with the same problem, but they seemed to be caused by forward declaration or circular inclusion. As far as I can tell, mine isn't.

queue.h

#include "pathing.h"
typedef struct _queue{
    struct queue* below;
    struct point_t value;
}queue;

point_t pop(queue* a);
point_t peek(queue a);
void add(queue* a, point_t pointer);

pathing.h

#ifndef _pathing_
#define _pathing_
typedef unsigned char byte_t;
typedef struct _point_t{
    int x;
    int y;
}point_t;

int exec(int argc,char* arg[]);
#endif

Solution

  • typedef struct _queue{
        // This is a typo. You are missing the _ before queue.
        // struct queue* below;
        struct _queue* below; 
        struct point_t value;
    }queue;
    

    Regarding point_t, there is no such thing as struct point_t in your code. You can use:

    struct _point_t value; 
    

    or

    point_t value;