C语言 错误:“list_node”之前的预期声明说明符或“...”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5001346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: expected declaration specifiers or ‘...’ before ‘list_node’
提问by pvinis
I have a catalog.h file with this
我有一个 catalog.h 文件
typedef struct node* list_node;
struct node
{
operationdesc op_ptr;
list_node next;
};
and a parser.h with this
和一个带有这个的 parser.h
#include "catalog.h"
int parse_query(char *input, list_node operation_list);
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 parser.h, and it's fine. Why do I get this error when the typedef is in catalog.h?
两个标题都有#ifndef, #define, #endif。编译器给了我这个错误:expected declaration specifiers or ‘...' before ‘list_node'在 parse_query 行上。怎么了?我试图将 typedef 放在 parser.h 中,这很好。当 typedef 在 catalog.h 中时,为什么会出现此错误?
回答by Timothy Jones
The error is this (from your comment):
错误是这样的(来自您的评论):
I had an #include "parser.h" in the catalog.h. I removed it, and now it compiles normally...
我在catalog.h 中有一个#include "parser.h"。我删除了它,现在它可以正常编译...
Assuming that #include "parser.h"was before the typedef in catalog.h, and you have a source file that includes catalog.hbefore 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.
假设#include "parser.h"在 typedef in 之前catalog.h,并且您有一个包含catalog.hbefore的源文件parser.h,那么在编译器包含时parser.h,typedef 尚不可用。最好重新排列头文件的内容,这样就不会出现循环依赖。
If this isn't an option, you can ensure that any source files that include these two files include parser.hfirst (or only).
如果这不是一个选项,您可以确保包含这两个文件的任何源文件parser.h首先(或仅包含)。
回答by Sandeep Bhat
Try this for catalog.h:
试试这个catalog.h:
typedef struct node_struct {
operationdesc op_ptr;
struct node_struct* next;
} node;
typedef node* list_node;

