当我从函数作用域(编译没有报错)到全局作用域声明 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 *’
注意最后一个警告(真的是一个注意事项):)