外部结构数组

发布于 2024-12-27 18:53:43 字数 295 浏览 1 评论 0原文

我有一个全局结构数组,如

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凤舞天涯 2025-01-03 18:53:43

在头文件中定义结构体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.

薆情海 2025-01-03 18:53:43

您必须在某处声明类型 struct _links 。

You have to declare a type struct _links somewhere.

寂寞清仓 2025-01-03 18:53:43

一个好的编程习惯是创建一个新文件 links.h ,其中包含

extern struct _links link[255][255][255];

在 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

extern struct _links link[255][255][255];

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文