指向结构 "undeclared (first use in this function)" 的指针
Pointer to struct "undeclared (first use in this function)"
我正在尝试用 C 实现链表,
我很难弄清楚为什么在编译时会出现以下错误:
entryList.c:7:11: error: 'tmp' undeclared (first use in this function)
entry * tmp = NULL;
entryList.c:7:11: note: each undeclared identifier is reported only once for
each function it appears in
^
我已经为这个程序写了几个链表,它们都使用类似的语法,但编译器只抱怨这个。
我在 header.h 中有我的结构定义:
/*definition of entry type*/
typedef struct entry
{
char * label;
short int address;
struct entry * next;
} entry;
并且在 entryList.c 中,我正在编写一个函数来将节点添加到链表中。
#include "header.h"
static entry * head = NULL;
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
char * label = NULL;
tmp = malloc(sizeof(entry));
label = malloc(sizeof(char)*MAX_LINE);
strcpy(tmp->label, entry);
tmp->address = 0;
tmp->next = NULL;
if (!head)
{
head = tmp;
}
else
{
entry * p = head;
while (p->next)
p = p->next;
p->next = tmp;
}
}
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
您有一个参数和一个名为 entry
的类型。将其中之一更改为其他内容。
我正在尝试用 C 实现链表, 我很难弄清楚为什么在编译时会出现以下错误:
entryList.c:7:11: error: 'tmp' undeclared (first use in this function)
entry * tmp = NULL;
entryList.c:7:11: note: each undeclared identifier is reported only once for
each function it appears in
^
我已经为这个程序写了几个链表,它们都使用类似的语法,但编译器只抱怨这个。
我在 header.h 中有我的结构定义:
/*definition of entry type*/
typedef struct entry
{
char * label;
short int address;
struct entry * next;
} entry;
并且在 entryList.c 中,我正在编写一个函数来将节点添加到链表中。
#include "header.h"
static entry * head = NULL;
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
char * label = NULL;
tmp = malloc(sizeof(entry));
label = malloc(sizeof(char)*MAX_LINE);
strcpy(tmp->label, entry);
tmp->address = 0;
tmp->next = NULL;
if (!head)
{
head = tmp;
}
else
{
entry * p = head;
while (p->next)
p = p->next;
p->next = tmp;
}
}
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
您有一个参数和一个名为 entry
的类型。将其中之一更改为其他内容。