本文介绍了数组类型在编译时具有不完整的元素类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

In our class we are to implement a kernel built on a bochs simulator.

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

One of the subtasks is to implement fixed priority scheduling. Previously our scheduler was only one thread queue, but now i wanted to make an array of thread queues.

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

But my array keeps getting a comiler error "array type has incomplete element type" i posted some of the code below, can anyone see the problem.

kernel.h

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

kernel.c

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

sysdefines.h

sysdefines.h

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

threadqueue.h

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

You need to have the definition of the structure whos array you create before creating the array(the compiler needs to see the definition of type whos array you create), othewise the type is an Incomplete type for the compiler and it does not know the memory layout of that type and hence cannot create an array of it.

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

You should put the definition of the structure in a header file and include it whichever files you want to refer to structure elements or do some action which needs the compiler to know of the structure layout.

这篇关于数组类型在编译时具有不完整的元素类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:06