2011-02-15 126 views
7

我有这个错误:预期的声明说明符或 '...' 前 'list_node'

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

一个catalog.h文件和parser.h这个

#include "catalog.h" 

int parse_query(char *input, list_node operation_list); 

两个头有#ifndef,#define,#endif。 编译器给了我这个错误:parse_query行上的expected declaration specifiers or ‘...’ before ‘list_node’。 什么事情? 我试图把typedef放在parser.h中,并没有问题。为什么当typedef位于catalog.h中时会出现此错误?

+0

实际上,我在catalog.h中有一个#include“parser.h”。我删除它,现在它编译通常...我想它试图加载parse_query定义之前的typedef和结构定义..? – pvinis 2011-02-15 08:48:04

+0

catalog.h中的#ifndef究竟是什么样的?尝试cc -E查看预处理器输出,以查看list_node是否真正在parse_query行的点处定义。 – 2011-02-15 08:49:02

回答

0

尝试此catalog.h

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

typedef node* list_node; 
6

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

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

假设#include "parser.h"是的typedef前catalog.h,和你有一个源文件包括在parser.h之前的catalog.h,那么在编译器包含parser.h时,typedef尚不可用。 这可能是最好的重新排列头文件的内容,以便你没有循环依赖。

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

相关问题