当前位置: 技术问答>linux和unix
一个小问题关于dereferencing pointer to incomplete type的
来源: 互联网 发布时间:2016-05-08
本文导语: 在我下面的CODE中 当我COMPILE的时候 我标记//的4行会出现这样的错误 dereferencing pointer to incomplete type 请问要怎么改正呢 谢谢 #define NULL 0 #include #include #include #include #include #include #include struct task_queu...
在我下面的CODE中
当我COMPILE的时候 我标记//的4行会出现这样的错误 dereferencing pointer to incomplete type
请问要怎么改正呢 谢谢
#define NULL 0
#include
#include
#include
#include
#include
#include
#include
struct task_queue *runQ;//runing queue of the task
struct task_queue *readyQ;//ready queue
int main(int argc, char *argv[]){
runQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
// runQ->task = NULL;
// runQ->next = NULL;
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
// readyQ->task = NULL;
// readyQ->next = NULL;
}
struct task{
int arrival_t,burst_t,priority, remainQt;
int pid;
};
struct task_queue{//task queue structure
struct task *task;
struct task_queue *next;
};
当我COMPILE的时候 我标记//的4行会出现这样的错误 dereferencing pointer to incomplete type
请问要怎么改正呢 谢谢
#define NULL 0
#include
#include
#include
#include
#include
#include
#include
struct task_queue *runQ;//runing queue of the task
struct task_queue *readyQ;//ready queue
int main(int argc, char *argv[]){
runQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
// runQ->task = NULL;
// runQ->next = NULL;
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
// readyQ->task = NULL;
// readyQ->next = NULL;
}
struct task{
int arrival_t,burst_t,priority, remainQt;
int pid;
};
struct task_queue{//task queue structure
struct task *task;
struct task_queue *next;
};
|
正解:
不过dereferencing pointer to incomplete type 的原因是
结构的声明位置不当.
struct task{
int arrival_t,burst_t,priority, remainQt;
int pid;
};
struct task_queue{//task queue structure
struct task *task;
struct task_queue *next;
};
放在:
struct task_queue *runQ;//runing queue of the task
struct task_queue *readyQ;//ready queue
之前就好了.
|
runQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
改成
runQ = (struct task_queue *)malloc(sizeof(struct task_queue));
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
改成
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue));
改成
runQ = (struct task_queue *)malloc(sizeof(struct task_queue));
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue *));
改成
readyQ = (struct task_queue *)malloc(sizeof(struct task_queue));