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
我不太确定,如果我跟着你,它是什么你期望? –