【发布时间】:2013-03-24 12:59:02
【问题描述】:
我有以下我感兴趣的源代码。
#include <stdio.h>
extern int foo;
int foo = 32;
int main()
{
printf("%d", foo);
}
这是一段完全正常的代码,当我用它编译时
gcc -Wall -Wextra -pedantic foo.c
我没有收到任何警告。
这看起来很奇怪,因为变量在同一个文件中既定义为外部变量,又定义为全局变量。 我很确定链接器很容易在同一个文件中找到外部变量的引用,但它看起来不像是编码错误吗?如果是这样,为什么编译器不对此发出警告?
【问题讨论】:
标签: c gcc global-variables extern