<分区>
我收到段错误,同时将结构的成员与 0 进行比较。 令人困惑的部分是比较确实发生了几次,然后是暗恋。
请帮忙。 代码:
Dword addup(void)
{
Symbol *curr=NULL;
Dword ans=0;
plast->next=NULL;
if( (phead==NULL) || (plast==NULL) )/*checks that the global pointer to the head & tail is not null.*/
return 0;
curr=phead;
printf("point 1 in addup()********\n");
for( ; curr!=NULL ; curr=curr->next )
{
if(curr!=NULL)
{
if( ((curr->feature.oper)==0) && ((curr->feature.ext)==0) )/*crash here !*/
{
puts("point 2AA in addup()********");
curr->adess=+IC;
ans++;
}
puts("point 2B in addup()********");
}
if((curr->next)==NULL)
break;
}
if( (curr!=NULL) && (plast!=NULL) )
{
if(curr==plast)/*meaning all the list been searched.*/
return ans;
}
return (-1); }
和符号:
typedef struct snode {
char label[MAXLABEL];
Dword adess;
struct
{
unsigned int ext:1;
unsigned int oper:1;
}feature;
struct snode *next;
}Symbol;
感谢所有提供帮助的人!
**第一次编辑- phead 是指向列表头部的指针。 plast 是指向列表最后一个节点(Symbol)的指针。 在其他函数中初始化。 plast->next 始终为 null。(这是在函数的开头 - 因为我想确定)。
**第二次编辑- 创建函数 -
void csymbl(Dword addess, char *name, Dword ext, Dword ope ){
tempnode.adess=addess;/*tempnode is a global Symbol,that been used to insert new nodes.*/
strcpy(tempnode.label,name);
tempnode.feature.ext=ext;
tempnode.feature.oper=ope;
tempnode.next=NULL;}
以及将它连接到列表的函数:
void addsymbol(Symbol a){
if(phead==NULL)/*if phead point to NULL - meaning this is the first symbol been entered & up now the linked list was empty. */
{
phead=&a;
plast=phead;
}
else if(plast==phead)/*If plast point to phead,than there is only one symbol in the list(up to now).*/
{
plast=&a;
phead->next=plast;
plast->next=NULL;
}
else
{
plast->next=&a;
plast=plast->next;
plast->next=NULL;
}}