2013-07-24 57 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

相关问题