外部结构数组
我有一个全局结构数组,如
struct _links link[255][255][255];
我的 main.c 中 所示。这个结构体数组也在另一个文件action.c中使用,我尝试在action.c中将其声明为extern,即,
extern struct _links link[255][255][255];
但是,我收到错误消息“数组类型具有不完整的元素类型”。我不明白那是什么意思。我该如何解决这个问题?
谢谢。
I have a global array of structure declared as
struct _links link[255][255][255];
in my main.c. This array of structures is also used in another file, action.c, and I tried to declare it in action.c as an extern, i.e.
extern struct _links link[255][255][255];
However, I got the error message "array type has incomplete element type". I don't understand what that means. How can I resolve this problem?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在头文件中定义结构体
struct _links
;将其包含在 my_main.c 和 action.c 中,单独编译它们并链接它们。它无需内置数据类型的头文件即可工作。但对于用户定义的数据类型,需要头文件。
Define your structure
struct _links
in a header file; include that in both my_main.c and action.c, compile them seperately and link them.It works without header file for in-built data types. but for user defined data types, header file is needed.
您必须在某处声明类型 struct _links 。
You have to declare a type
struct _links
somewhere.一个好的编程习惯是创建一个新文件 links.h ,其中包含
在 main.c 和 action.c 上包含此文件。
不要忘记只定义变量一次。
有关 extern 关键字的更多信息,请查看这篇文章 https://stackoverflow.com/a/1433387/1117720
a good programming practice is to create a new file links.h which contains
include this file on both main.c and action.c .
do not forget to define the variable only once.
for more informations about extern keyword,take a look at this post https://stackoverflow.com/a/1433387/1117720