2
當我編譯上VC++ 10以下來源,該i
與靜態鏈接被分配給42
但在G ++ 4.5.1所述的i
與source2.cpp外部鏈接被分配給42
。不同行爲
根據標準,什麼應該是標準確認行爲的任何想法或爲什麼?
// source1.cpp
#include <iostream>
static int i = 0;
int h();
void foo()
{
int i;
{
extern int i;
i = 42;
}
}
int main()
{
foo();
std::cout << i << std::endl;
std::cout << h() << std::endl;
}
// source2.cpp
int i;
int h() { return i; }
你是如何知道價值的。我沒有看到任何打印聲明。 –
+1鏈接到鼓舞這個問題的問題:http://stackoverflow.com/questions/8235870/no-linkage-at-block-scope/8235898#8235898 – sehe
我不太確定,如果我跟着你,它是什麼你期望? –