【发布时间】:2013-11-09 13:30:17
【问题描述】:
我有 lexer.c 文件,它应该包含在另一个 .c 文件中。它有
int getToken(string *attribute) {}
函数和原型相同。我还有帮助 str.c 文件来简化字符串的工作。它有带有 string 类型声明的头文件:
typedef struct {
char* str; //string with \0 at the end
int length; //length of the string
int allocated; //allocated memory size
} string;
所以,lexer.h 包含在主文件中。然后 lexer.c 开始于:
#include "str.h"
#include "lexer.h"
据我了解,在包含 str.h 后,lexer.c 和 lexer.h 可以看到类型 string。 但是我在头文件中的原型有编译错误:
./lexer.h:65:14: error: unknown type name 'string'
int getToken(string *attribute);
^
1 error generated.
如何在头文件中使用这种类型?
【问题讨论】:
-
检查 #ifdef 或其他原因,您的 typedef 可能会被排除在外...与您的问题无关,但
I have lexer.c file, which should be included to another .c file.- 如果那不是类型...。不要 #include one 。 c 变成另一个。有时它可能工作正常,但作为一种模式遵循它最终会导致问题。 -
你为什么不把它简单化,你的自定义声明到一个通用的头文件中,并将它包含在所需的 .c 文件中。
-
@mah 对不起我的写作风格,我的意思是通过 lexer.h 头文件包含到另一个 .c 文件中
标签: c typedef header-files function-prototypes