为什么"const extern"会出错?

msc*_*msc 4 c gcc const global-variables extern

以下代码正常工作:

#include <stdio.h>

extern int foo; // Without constant
int foo = 42;

int main() 
{
    printf("%d\n",foo);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,下面的代码会出错:

#include <stdio.h>

const extern int foo; // With constant
int foo = 42;

int main() 
{
    printf("%d\n",foo);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

那么,为什么会const extern出错呢?

hac*_*cks 6

标准说:
C11-§6.7/ 4

引用同一对象或函数的同一范围内的所有声明都应指定兼容类型

const int并且int不兼容foo同一范围内的同一对象.