c - 数组类型编译时出现不完整元素类型错误

标签 c compiler-construction

在我们的类(class)中,我们将实现一个基于 bochs 模拟器构建的内核。

子任务之一是实现固定优先级调度。以前我们的调度程序只有一个线程队列,但现在我想制作一组线程队列。

但是我的数组不断收到编译器错误“数组类型具有不完整的元素类型”,我发布了下面的一些代码,任何人都可以看到问题。

内核.h

...
extern struct thread_queue
ready_queue_table[MAX_SYS_PRIORITY];
...

内核.c

...
#include <sysdefines.h>
#include "threadqueue.h"
...
struct thread_queue
ready_queue_table[MAX_SYS_PRIORITY];
...

sysdefines.h

...
#define MAX_SYS_PRIORITY         (5)
...

threadqueue.h

...
struct thread_queue
{
 int head;  /*!< The index to the head of the thread queue.
                 Is -1 if queue is empty. */
 int tail;  /*!< The index to the tail of the thread queue.
                 Is -1 if queue is empty. */
};
...

最佳答案

在创建数组之前,你需要有你创建的结构体whos数组的定义(编译器需要查看你创建的类型whos数组的定义),否则该类型是一个不完整类型对于编译器来说,它不知道该类型的内存布局,因此无法创建它的数组。

您应该将结构的定义放在头文件中,并将其包含在您想要引用结构元素或执行某些需要编译器了解结构布局的操作的任何文件中。

关于c - 数组类型编译时出现不完整元素类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10386539/

相关文章:

c - 使用 C 语言实现 Web 服务

parsing - 以下设定程序

parsing - 左关联运算符能否以自上而下的 LL(1) 解析器可以理解的方式表达?

编译器优化 : const on non-pointer function arguments in C

c - 为什么我不能乘以 float ?

c++ - 8192位异或加密?

c++ - 如何同时编辑函数签名

compiler-construction - 为 x86 处理器生成程序集

ubuntu - 构建 LLVM 3.4 和 clang 时出错

无法使用 ld 链接目标文件 - Mac OS X