2011-02-15 139 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第一(或唯一)。

相關問題