我試過這三個小程序的版本,並且得到了一些有趣的結果。任何人都可以幫助我理解每種情況下的編譯器行爲。瞭解程序和GCC編譯器行爲中變量的多重聲明
version 1.0
int A;
int A;
int A;
int main()
{
return 0;
}
Result: Got compiled with one copy of A in BSS.
Version 2.0
int main()
{
int A;
int A;
int A;
return 0;
}
Result: Failed to compile with complaining for re-declaration.
Version 3.0
int A;
int main()
{
static int A;
return0;
}
result: Compiled with two copy of A in BSS. one is A and another a.<some numeric tag>.
Satpal查看這兩個:[** 6.9.2外部對象定義**](http://c0x.coding-guidelines.com/6.9.2.html)和[**爲什麼變量不能是在C **中的兩個文件中定義兩次](http://stackoverflow.com/questions/4990315/why-a-variable-cant-be-defined-twice-in-2-files-in-c) –