错误:C中的未知类型。当包含所有必需的头文件时,原因是什么?
因此,我无法解决以下问题: 我正在获取orderPtr的未知类型,它是struct Order的typedef,尽管我已经包含声明此类型的头文件。 以下是队列中的代码。h:错误:C中的未知类型。当包含所有必需的头文件时,原因是什么?,c,C,因此,我无法解决以下问题: 我正在获取orderPtr的未知类型,它是struct Order的typedef,尽管我已经包含声明此类型的头文件。 以下是队列中的代码。h: #ifndef QUEUE_H #define QUEUE_H #include <stdio.h> #include "book.h" #include "queue_node.h" /* * Queue structure for consumers threads */ typedef struct
#ifndef QUEUE_H
#define QUEUE_H
#include <stdio.h>
#include "book.h"
#include "queue_node.h"
/*
* Queue structure for consumers threads
*/
typedef struct queue {
pthread_mutex_t mutex;
pthread_cond_t notempty;
struct queue_node *rear;
} queuePtr;
void queue_enqueue(queuePtr *, orderPtr *);
orderPtr *queue_dequeue(queuePtr *queue);
#endif
\ifndef队列
#定义队列
#包括
#包括“book.h”
#包括“queue_node.h”
/*
*消费者线程的队列结构
*/
typedef结构队列{
pthread_mutex_t mutex;
pthread_cond_t notempty;
结构队列节点*后部;
}排队器;
无效队列(queuePtr*,orderPtr*);
orderPtr*队列(queuePtr*队列);;
#恩迪夫
在这里,这种类型在book.h中声明:
#ifndef BOOK_H
#define BOOK_H
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <pthread.h>
#include "uthash.h"
#include "customer.h"
#include <errno.h>
#include <unistd.h>
#include "queue.h"
typedef struct order {
char *title;
double price;
char *idnum;
char *category;
} orderPtr;
void order_destroy(orderPtr *);
orderPtr * order_create(char *, double, char *, char *);
#endif
\ifndef BOOK\u H
#定义书
#包括
#包括
#包括
#包括
#包括
#包括“uthash.h”
#包括“customer.h”
#包括
#包括
#包括“queue.h”
typedef结构顺序{
字符*标题;
双倍价格;
char*idnum;
字符*类别;
}orderPtr;
无效订单(订单PTR*);
orderPtr*创建订单(char*,double,char*,char*);
#恩迪夫
如果遵循包含链,则如下所示:
main.c
包括book.h
book.h
包括顶部的queue.h
(在orderPtr的typedef之前)
queue.h
尝试使用尚未被typedef'd=error的orderPtr
orderPtr
的typedefqueue.h
中执行以下操作:
/*
* Queue structure for consumers threads
*/
typedef struct queue {
pthread_mutex_t mutex;
pthread_cond_t notempty;
struct queue_node *rear;
} queuePtr;
struct orderPtr; // Forward declaration
// The use of struct orderPtr * is allowed because it is a pointer.
// If it wasn't a pointer, it would be an error because the size
// would be unknown.
void queue_enqueue(queuePtr *, struct orderPtr *);
struct orderPtr *queue_dequeue(queuePtr *queue);
如果遵循包含链,则如下所示:
main.c
包括book.h
book.h
包括顶部的queue.h
(在orderPtr的typedef之前)
queue.h
尝试使用尚未被typedef'd=error的orderPtr
orderPtr
的typedefqueue.h
中执行以下操作:
/*
* Queue structure for consumers threads
*/
typedef struct queue {
pthread_mutex_t mutex;
pthread_cond_t notempty;
struct queue_node *rear;
} queuePtr;
struct orderPtr; // Forward declaration
// The use of struct orderPtr * is allowed because it is a pointer.
// If it wasn't a pointer, it would be an error because the size
// would be unknown.
void queue_enqueue(queuePtr *, struct orderPtr *);
struct orderPtr *queue_dequeue(queuePtr *queue);
如果遵循包含链,则如下所示:
main.c
包括book.h
book.h
包括顶部的queue.h
(在orderPtr的typedef之前)
queue.h
尝试使用尚未被typedef'd=error的orderPtr
orderPtr
的typedefqueue.h
中执行以下操作:
/*
* Queue structure for consumers threads
*/
typedef struct queue {
pthread_mutex_t mutex;
pthread_cond_t notempty;
struct queue_node *rear;
} queuePtr;
struct orderPtr; // Forward declaration
// The use of struct orderPtr * is allowed because it is a pointer.
// If it wasn't a pointer, it would be an error because the size
// would be unknown.
void queue_enqueue(queuePtr *, struct orderPtr *);
struct orderPtr *queue_dequeue(queuePtr *queue);
如果遵循包含链,则如下所示:
main.c
包括book.h
book.h
包括顶部的queue.h
(在orderPtr的typedef之前)
queue.h
尝试使用尚未被typedef'd=error的orderPtr
orderPtr
的typedefqueue.h
中执行以下操作:
/*
* Queue structure for consumers threads
*/
typedef struct queue {
pthread_mutex_t mutex;
pthread_cond_t notempty;
struct queue_node *rear;
} queuePtr;
struct orderPtr; // Forward declaration
// The use of struct orderPtr * is allowed because it is a pointer.
// If it wasn't a pointer, it would be an error because the size
// would be unknown.
void queue_enqueue(queuePtr *, struct orderPtr *);
struct orderPtr *queue_dequeue(queuePtr *queue);
您有一个循环引用,
book.h
包括queue.h
和queue.h
包括book.h
。我不太确定您希望编译器对此做些什么:)@JoachimIsaksson谢谢!我真的不知道结构定义的这一部分:'}queuePtr;'不是生成指向结构类型的指针,而是生成结构类型。您可以将行更改为:'}*queuePtr--或者——您可以调用函数:void order_destroy(orderPtr*);使用订单销毁(&myOrder);如果myOrder是链表中结构的实例,则指向列表中下一个条目的指针应与结构本身的类型相同,因此此行为:struct queue_node*rear;预期为:结构队列*后部;您有一个循环引用,book.h
包括queue.h
和queue.h
包括book.h
。我不太确定您希望编译器对此做些什么:)@JoachimIsaksson谢谢!我真的不知道结构定义的这一部分:'}queuePtr;'不是生成指向结构类型的指针,而是生成结构类型。您可以将行更改为:'}*queuePtr--或者——您可以调用函数:void order_destroy(orderPtr*);使用订单销毁(&myOrder);如果myOrder是链表中结构的实例,则指向列表中下一个条目的指针应与结构本身的类型相同,因此此行为:struct queue_node*rear;预期为:结构队列*后部;您有一个循环引用,book.h
包括queue.h
和queue.h
包括book.h
。我不太确定您希望编译器对此做些什么:)@JoachimIsaksson谢谢!我真的不知道结构定义的这一部分:'}queuePtr;'不是生成指向结构类型的指针,而是生成结构类型。您可以将行更改为:'}*queuePtr--或者——您可以调用函数:void order_destroy(orderPtr*);使用订单销毁(&myOrder);如果myOrder是链表中结构的实例,则指向列表中下一个条目的指针应与结构本身的类型相同,因此此行为:struct queue_node*rear;预期为:结构队列*后部;您有一个循环引用,book.h
包括queue.h
和queue.h
包括book.h
。我不太确定您希望编译器对此做些什么:)@JoachimIsaksson谢谢!我真的不知道结构定义的这一部分:'}queuePtr;'不是生成指向结构类型的指针,而是生成结构类型。您可以将行更改为:'}*queuePtr--或者——您可以调用函数:void order_destroy(orderPtr*);使用订单销毁(&myOrder);其中,myOrder是链接中结构的实例