Error: expected declaration qualifiers or "... to" list_node

I have a catalog.h file with this

typedef struct node* list_node; struct node { operationdesc op_ptr; list_node next; }; 

and parser.h with this

 #include "catalog.h" int parse_query(char *input, list_node operation_list); 

Both headers have #ifndef , #define , #endif . The compiler gives me this error: expected declaration specifiers or '...' before 'list_node' in the parse_query line. What's the matter? I tried putting typedef in parser.h, and everything is fine. Why am I getting this error when typedef is in the .h directory?

+7
source share
2 answers

The error in this (from your comment):

I had #include "parser.h" in the .h directory. I deleted it and now it compiles fine ...

Assuming #include "parser.h" was before typedef in catalog.h , and you have a source file that includes catalog.h before parser.h , then while the compiler includes parser.h , typedef is not available same. It is probably best to reorder the contents of the header files so that you do not have a circular dependency.

If this is not an option, you can make sure that all source files containing these two files include parser.h first (or only).

+6
source

Try this for catalog.h :

 typedef struct node_struct { operationdesc op_ptr; struct node_struct* next; } node; typedef node* list_node; 
0
source

All Articles