关于 extern 关键字的使用

regarding the use of extern keyword

extern int var;

我知道当我们使用 extern 关键字和变量时,如下所示,不会为该变量分配内存。 (只是一个声明)

extern int i = 0;

而且我知道,如果我们声明一个 extern 变量并随该声明提供一个初始化程序,那么就会为该变量分配内存。

下面的程序也在打印 0

#include <stdio.h>
int i; // Can I treat this as declaration/definition?
int main()
{
    printf("%d ", i);
    return 0;
}

我感觉,这里变量i被赋值为0

如果(int i;如上所示)是定义,为什么下面的代码没有给出多重定义错误?

#include <stdio.h>
int i;
int i;
int i;
int main()
{
    printf("%d ", i);
    return 0;
}

没有显式初始化,全局space中的所有int i都称为暂定。但是,这在本地范围内是不允许的。

引用 C11 标准,章节 §6.9.2,外部对象定义

A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier static, constitutes a tentative definition. If a translation unit contains one or more tentative definitions for an identifier, and the translation unit contains no external definition for that identifier, then the behavior is exactly as if the translation unit contains a file scope declaration of that identifier, with the composite type as of the end of the translation unit, with an initializer equal to 0.