c - 期望 'struct netif *' 但参数类型为 'struct netif *'

标签 c

<分区>

当我从函数作用域(编译没有报错)到全局作用域声明 struct netif * 时,gcc 出现以下错误:

src/main.c:114:3: warning: passing argument 1 of 'low_level_init' from incompatible pointer type [enabled by default]
src/main.c:62:13: note: expected 'struct netif *' but argument is of type 'struct netif *'

为什么编译器会给出以下“无意义”的提示?

应为 'stuct netif *' 但参数类型为 'struct netif *'

最佳答案

这个“完整程序”

void foonetif(struct netif *dst) {
  if (dst) return;
  return;
}

struct netif {
  double bar;
};

int main(void) {
  struct netif *netif = 0; /* NULL */
  foonetif(netif);
  return 0;
}

gcc 10398683.c(gcc 版本 4.6.3)生成此输出,因此使用所有默认选项

10398683.c:1:22: warning: ‘struct netif’ declared inside parameter list [enabled by default]
10398683.c:1:22: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
10398683.c: In function ‘main’:
10398683.c:12:3: warning: passing argument 1 of ‘newnetif’ from incompatible pointer type [enabled by default]
10398683.c:1:6: note: expected ‘struct netif *’ but argument is of type ‘struct netif *’

注意最后一个警告(真的是一个注意事项):)

关于c - 期望 'struct netif *' 但参数类型为 'struct netif *',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10398683/

相关文章:

C++ 将 DWORD 分解为字符

将值从文件复制到主函数变量,以便可以使用它们

c - 从字符串中提取整数并将其保存到链表中

c - 暴露动态 IP 后面的本地网络服务器

c++ - C位运算题

C - 在 SPI 模式下初始化 SD 卡,始终读回 0xFF

c - 关于 "for(a, b&&c, d) {...}"和 "for(a, b, d) if(c) {...}"的区别

c - 将整数存储在字符缓冲区数组中变成二进制值

c - 为什么编译器分配的内存多于所需的内存?

c - 从文件或路径获取 FILE 扩展名