c - gcc:C 中未声明的变量,但已声明

标签 c variables gcc

下面是我正在编写的 C 程序的第一部分。然而,gcc 在编译期间抛出错误,结果是 setps1 均未声明,但它们已声明。我这个文件中的每个函数都遇到这个问题,我不知道出了什么问题。我需要做什么来解决这个问题?

该函数的具体错误:

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/

相关文章:

c - 使用 openMP 库运行 C 代码时出错

c - 链接器脚本错误: section overlap

c++ - 如何使用 Genlex 构建 OCaml 源代码

c - 单独构建C程序

c - 调度源阅读器 - 如何检测文件结尾?

PHP "Use of undefined constant"来自 $_POST

php - 将两个数组相互组合并从 MySQL 数据库中获取名称

mysql - 无法检测 where 子句中的整数值

C - 如何从c文件中删除与用户输入相同的字符串?

c++ - 避免重新定义预处理器变量