关于extern "C"的纳闷

关于extern "C"的疑惑
编译环境 vs2005
//a.h
extern "C"
{
const int g_i;
}
//a.cpp
extern "C"
{
const int g_i = 21;
}
编译报错:
错误 1 error C2734: “g_i”: 如果不是外部的,则必须初始化常量对象

但是如果修改为:
//a.h
extern "C" const int g_i;

//a.cpp
extern "C" const int g_i = 21;
编译通过。

两者做法应该是一样的呀,不明白,望解答!


------解决方案--------------------
编译器翻译问题,vs就这么规定的,换成g++就ok
------解决方案--------------------
两种做法就是在这一点上是不一样的呀!
这是非此即彼,可以推导的。
虽然,要找到出处,就只有你自己去翻标准啦,标准上是有明确说明的。
------解决方案--------------------
引用:
VS编译器的BUG多,是出了名的!

但是就楼主的例子来说,在头文件里声明变量,按惯例应该要声明为extern的。
------解决方案--------------------
 
Mixed-Language Programming with C++
Home 
------解决方案--------------------
  Overview 
------解决方案--------------------
  How Do I

C++ uses the same calling convention and parameter-passing techniques as C, but naming conventions are different because of C++ decoration of external symbols. By causing C++ to drop name decoration, the extern "C" syntax makes it possible for a C++ module to share data and routines with other languages.

The following example declares prn as an external function using the C naming convention. This declaration appears in C++ source code.

extern "C"
{
    void prn();
}

To call functions written in Fortran (or MASM), declare the function as you would in C and use a "C" linkage specification. For example, to call the Fortran function FACT from C++, declare it as follows:

extern "C" { int __stdcall FACT( int n ); }

The extern "C" syntax can be used to adjust a call from C++ to other languages, or to change the naming convention of C++ routines called from other languages. However, extern "C" can be used only from within C++. If the C++ code does not use extern "C" and cannot be changed, you can call C++ routines only by determining the name decoration and generating it from the other language. You can always determine the decoration by using the DUMPBIN utility. Use this approach only as a last resort, because the decoration scheme is not guaranteed to remain the same between versions.

Use of extern "C" has some restrictions: 

You cannot declare a member function with extern "C".


You can specify extern "C" for only one instance of an overloaded function; all other instances of an overloaded function have C++ linkage. 
For more information on the extern "C" linkage specification, see Linkage Specifications in C++ Language Reference.

------解决方案--------------------
定义常量的时候必须初始化
extern "C" const int g_i;
也应该报错才对。

难道 extern "C" const int g_i; 被等价于了 
extern "C"
{
extern const int g_i;
}

------解决方案--------------------
Compiler Error C2734
'identifier' : const object must be initialized if not extern
The identifier is declared const but not initialized or extern.

The following sample generates C2734:
// C2734.cpp
const int j;   // C2734
extern const int i;   // OK, declared as extern