问题描述
我有两个C文件,文件foo.c的功能和test_foo.c这考验的foo.c的功能。
I have two c files, foo.c with the functionality and test_foo.c which test the functions of foo.c.
是否有访问结构的typedef 办法BAR
我在test_foo.c foo.c的定义不使用头文件?到目前为止,我能够避免.h文件,使整个节目将包括foo.c.的谢谢你。
Is there a way to access the struct typedef BAR
I defined in foo.c in test_foo.c without using a header file? So far, I was able to avoid a h file so that the whole program would consist of foo.c. Thanks.
foo.c
typedef struct BAR_{...} bar;
BAR *bar_new(...) {..}
test_foo.c
extern BAR *bar_new(...)
错误:BAR
推荐答案
答案是,有一个,你应该使用头文件来代替。
您可以复制该结构的定义 typedef结构BAR _ {...}酒吧;
到 test_foo.c
,它将工作。但是,这会导致重复。
每一个解决方案,必须工作提供给编译器结构的 test_foo.c
的实施。
你也可以使用一个ADT,如果这适合你在这种情况下。
The answer is that there is one, and you should use an header file instead.You can copy the definition of the struct typedef struct BAR_{...} bar;
into test_foo.c
and it will work. But this causes duplication.Every solution that works must make the implementation of struct available to the compiler in test_foo.c
.You may also use an ADT if this suits you in this case.
这篇关于如何声明的extern typedef结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!