twisted logic: a global variable in one file refers to an extern variable but is also referred by that extern variable
问题 fileA.cpp: #include <iostream> extern int iA; extern int iB= iA; int main() { std::cout<<iA<<','<<iB; } fileB.cpp extern int iB; extern int iA = 2*iB; Compiled and linked and ran, out come in the debug and release mode is 0,0 My question is how it works, why there is no issue in linking stage? I'm using VC++2003. 回答1: The initialiser overrides the extern keyword, so there's nothing "magical" about this: you're just declaring and defining two completely unrelated variables in different