下面是我正在编写的 C 程序的第一部分。然而,gcc 在编译期间抛出错误,结果是 set
、p
和 s1
均未声明,但它们已声明。我这个文件中的每个函数都遇到这个问题,我不知道出了什么问题。我需要做什么来解决这个问题?
该函数的具体错误:
a9.c: In function `makeaset':
a9.c:23: error: `set' undeclared (first use in this function)
a9.c:23: error: (Each undeclared identifier is reported only once
a9.c:23: error: for each function it appears in.)
a9.c:23: error: `p' undeclared (first use in this function)
a9.c:34: error: `s1' undeclared (first use in this function)
代码片段:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 32
struct set {
char *data;
int count;
};
typedef struct set set;
void makeaset(set **s1)
{
int i;
set *p;
p = NULL;
p = malloc(sizeof(set));
if (p) {
p->data = malloc(SIZE);
if (p->data) {
for (i = 0; i < SIZE; i++)
p->data[i] = 0;
p->count = 0;
}
}
*s1 = p;
}
最佳答案
尝试
struct set_struct {
char *data;
int count;
};
typedef struct set_struct set;
或类似的东西。
关于c - gcc:C 中未声明的变量,但已声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20184144/