I have lexer.c file, which should be included to another .c file. It have

int getToken(string *attribute) {}

function and same prototype in lexer.h header file. Also i have helper str.c file for simplify work with strings. It has header file with declaration of type string:

typedef struct {
    char* str;      //string with \0 at the end
    int length;     //length of the string
    int allocated;  //allocated memory size
} string;

So, lexer.h included from main file. Then lexer.c starts with:

#include "str.h"
#include "lexer.h"

As i understanding, after including str.h type string is visible for lexer.c and lexer.h. But i have compilation error at the prototype in header file:

./lexer.h:65:14: error: unknown type name 'string'
int getToken(string *attribute);
             ^
1 error generated.

How can i use this type in header file?

有帮助吗?

解决方案

I am not clear now which files include which. Let me try to recapitulate this:

  • lexer.c includes str.h and lexer.h
  • main.c includes lexer.h

Is that right? In this case, main.c cannot be compiled as, indeed, the definition of the string type is missing.

As lexer.h always requires str.h to be included, it might be a good idea to out #include "str.h" into this header file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top