開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
void foo(){
static int x;
}
int main ()
{
foo();
return 0;
}
問題是這樣的。 在foo function 中,static 變數x ,會被放在
memory 的 data section 中(或是有些人說的golable 區域中)。
問題: foo() return 後,從stack 裡移除之後。
1. 就我知道,static 變數x ,仍然還在data section 裡面。
x 位址仍然有效。
2. 如果上面的想法是對的。 那這樣如果一個大程式,
我看很多fucntion 都用static 變數在做事。這樣不是data section 越長越大,
沒人清那些垃圾?這樣是對的嗎?
請教了。
謝謝
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):