c - 警告 : ‘struct user_data_s’ declared inside parameter list

标签 c

我收到这个错误:

transform.c:23: warning: ‘struct user_data_s’ declared inside parameter list
transform.c:23: warning: its scope is only this definition or declaration, which is probably not what you want

我认为这是因为我有一个包含结构的结构。

这就是我想要做的:

void f2(struct user_data_s* data) {
  printf("Number %i\n", data->L);
}

void f1(struct user_data_s* data) {
  printf("Number %i\n", data->L);
  f2(data);
}

f1 中的 printf 有效,但是行

void f2(struct user_data_s* data) {

给出错误。

有谁知道我该如何解决这个问题?

最佳答案

您已在 f2f1 声明之间(或可能之后)声明了您的结构。移动您的结构声明,使其位于两个声明之前。

也就是说:

struct user_data_s
{
    int L;
};

void f2(struct user_data_s* data) {
      printf("Number %i\n", data->L);
}

void f1(struct user_data_s* data) {
      printf("Number %i\n", data->L);
        f2(data);
}

编译没有错误,但是

void f2(struct user_data_s* data) {
      printf("Number %i\n", data->L);
}


struct user_data_s
{
    int L;
};

void f1(struct user_data_s* data) {
      printf("Number %i\n", data->L);
        f2(data);
}

不会编译,因为 f2 无法知道 struct user_data_s 是什么。

您可能习惯于使用高级语言进行编程,这种语言允许您将声明/定义放在几乎任何地方(例如 C# 或 Python),但不幸的是,C 是严格自上而下编译的。

关于c - 警告 : ‘struct user_data_s’ declared inside parameter list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1719662/

相关文章:

c - 函数指针不兼容的指针类型 void (*)(void *) from void (my_type *)

c - 为什么我的 C 函数无法处理标点符号?

c - 在 C 中,我查找回文的代码要么不打印出所有字符,要么缺少单个字符,要么重复字符?

c - 地址空间布局随机化是否应用于 fork 进程

c - 返回一个 float 变量会失去其在 C 中的精度

c - execvp系统调用问题

c - 使用 scanf 在 C 中向后打印字符串

c - 可以以编程方式更新的系统全局计数器(在各种 Linux 版本上)?

c - 禁用 DejaGnu 选项

c - 避免 C 宏中的冗余