c/c++语言开发共享编译时,数组类型具有不完整的元素类型错误

在我们的课程中,我们将实现在bochs模拟器上构建的内核。

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

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

kernel.h当

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

kernel.c

 ... #include  #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数组的定义),否则类型是编译器的不完整类型 ,它不知道内存该类型的布局因此无法创建它的数组。

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

    kernel.h你有这个:

     extern struct thread_queue ready_queue_table[MAX_SYS_PRIORITY]; 

    我怀疑有一些事情包括kernel.h ,其中还没有包含threadqueue.h 。 我想你要么需要将#include "threadqueue.h"添加到kernel.h要么删除那个extern

    但所有这些只是猜测,因为代码片段非常稀疏。

      以上就是c/c++开发分享编译时,数组类型具有不完整的元素类型错误相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522131.html

      (0)
      上一篇 2020年12月9日
      下一篇 2020年12月9日

      精彩推荐