When I compile the following sources on VC++ 10, The i
with static linkage gets assigned to 42
But on G++ 4.5.1, The i
with external linkage in source2.cpp gets assigned to 42
.
Any ideas on what should be the standard confirming behavior according to the Standard or why?
// 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; }