错误:预期的声明说明符或'...''list_node“前 [英] error: expected declaration specifiers or ‘...’ before ‘list_node’

查看:416
本文介绍了错误:预期的声明说明符或'...''list_node“前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个catalog.h文件

I have a catalog.h file with this

typedef struct node* list_node;
struct node
{
    operationdesc op_ptr;
    list_node next;
};

和跟这个有parser.h

and a parser.h with this

#include "catalog.h"

int parse_query(char *input, list_node operation_list);

两个头都的#ifndef和#define的#endif。
编译器给我这个错误:预期的声明说明符或'...''list_node'之前。在parse_query线。
怎么了?
我试图把的typedef在parser.h,它的罚款。为什么当的typedef在catalog.h我得到这个错误?

Both headers have #ifndef, #define, #endif. The compiler gives me this error: expected declaration specifiers or ‘...’ before ‘list_node’. on the parse_query line. What's the matter? I tried to put the typedef in the parser.h, and it's fine. Why do I get this error when the typedef is in the catalog.h?

感谢

推荐答案

的错误是这样(从您的评论):

The error is this (from your comment):

我曾在一个catalog.h的#includeparser.h。我删除了它,现在会正常编译...

I had an #include "parser.h" in the catalog.h. I removed it, and now it compiles normally...

假设的#includeparser.h catalog.h 自定义类型之前,你有包括源文件 catalog.h parser.h ,然后在编译器包括<$ C $时间C> parser.h ,该类型定义是尚未公布。 这可能是最好的重新排列头文件的内容,这样你没有一个循环依赖你。

Assuming that #include "parser.h" was before the typedef in catalog.h, and you have a source file that includes catalog.h before parser.h, then at the time the compiler includes parser.h, the typedef isn't available yet. It's probably best to rearrange the contents of the header files so that you don't have a circular dependency.

如果这不是一种选择,可以确保包括这两个文件的源文件包括 parser.h 第一个(或唯一的)。

If this isn't an option, you can ensure that any source files that include these two files include parser.h first (or only).

这篇关于错误:预期的声明说明符或'...''list_node“前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆