作者gn00618777 (非常念舊)
看板C_and_CPP
標題[問題] C在記憶體的分布
時間Tue Jul 31 14:32:13 2018
我參考網路上的資訊
A:
int main() {
const static int x = 1; //放於.data段唯讀區
return 0;
}
B:
int main() {
return 0;
}
A的結果
text data bss dec hex filename
1103 544 8 1655 677 a.out
B的結果
text data bss dec hex filename
1099 544 8 1651 673 a.out
我在linux上 size a.out A和B的差異,照理說只有.data會有差異,為何影響到 text
而且data完全沒變動? 我甚至宣告一個
int a[] = {1,2,3}; 一樣會影響到 text, 這個區域變數應該算是在 stack 中吧!?
為什麼呢? 謝謝指教。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.69.181
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1533018738.A.298.html
※ 編輯: gn00618777 (61.220.69.181), 07/31/2018 15:07:59
※ 編輯: gn00618777 (61.220.69.181), 07/31/2018 15:51:43
→ sarafciel: size --format=SysV [objfile] 07/31 16:26
→ gn00618777: 謝謝你 07/31 18:25