Search code examples
cvisual-studio-macros

Macro's "incomplete type not allowed" error?


I have defined a macro having two parameter as given below:

#define DO_LIST_HEADER(Titem,MAX) typedef struct  {\
       int count;\
       Titem array[MAX];\
} TOrderedList##Titem;\
    \
void initialize_list##Titem(TOrderedList *list);\
int insert_item##Titem(TOrderedList *list, Titem item);\
int retrieve_ith##Titem(const TOrderedList *list, int i, Titem *item);\
int number_of_items##Titem(const TOrderedList *list);\
int list_empty##Titem(const TOrderedList *list);

This was in a header file and when I try to 'call' this macro from another .c file including the header in it.

typedef Ttime Titem;

DO_LIST_HEADER(Ttime,10)

Here I get an error that says incomplete type not allowed.

Why am I getting this type of error?

DO_LIST_HEADER macro contains function prototype containing Ttime as parameter.


Solution

  • The type names in the function declarations need to be pasted with the ##Titem term too:

    #define DO_LIST_HEADER(Titem,MAX) typedef struct  {\
           int count;\
           Titem array[MAX];\
    } TOrderedList##Titem;\
        \
    void initialize_list##Titem(TOrderedList##Titem *list);\
    int insert_item##Titem(TOrderedList##Titem *list, Titem item);\
    int retrieve_ith##Titem(const TOrderedList##Titem *list, int i, Titem *item);\
    int number_of_items##Titem(const TOrderedList##Titem *list);\
    int list_empty##Titem(const TOrderedList##Titem *list);