2013-07-24 55 views
1

我經歷了其他文章,但沒有像我的問題。 我試圖從一個文件(1.l)訪問結構。下面顯示的是我在文件1.l中對我的結構的聲明和定義。取消引用指向結構中不完整類型的指針

< 1.L>

struct node 
{ 
char words[50]; 
struct node *next; 
}; 

struct node *head = NULL; 
struct node *head1 = NULL; 

從我試圖訪問該文件是2.l. 2.l如下所示。

%{ 

#include "y.tab.h" 
extern struct node *head1; 

%} 

%x SECTION 

%% 

"#pragma omp section" { BEGIN SECTION; yyless(0); } 

<SECTION>"#pragma omp section" { 
           fprintf(yyout,"meta_fork"); 
           while(head1 != NULL) 
           { 
    \\error in this line   fprintf(yyout,"shared(%s)",head1->words); 
    \\error in this line   head1 = head1->next; 
           } 
           } 
%% 

該錯誤是取消引用指向不完整類型的指針。

任何人都可以請告訴我這裏有什麼問題。謝謝。

+0

我也嘗試過像下面那樣定義我的stuct * head1,但仍然得到相同的錯誤。 struct node * head1 { char words [50]; struct node * next; }; – Sunny

回答

1

除非struct node的定義出現在< 2.l>中,編譯器將不知道它具有哪些成員。您應該將定義移動到頭文件,然後將其包含在兩個lex文件中。

+0

謝謝。所以你的意思是定義必須在兩個文件中?我必須訪問已經保存在1.l的head1中的東西。我可以做嗎? – Sunny

+0

基本上,是的。 –

+0

我定義了結構節點定義並將其放在頭文件中,然後嘗試。它說,未定義的引用'head1'。請幫忙。 – Sunny

相關問題