看板 C_and_CPP 關於我們 聯絡資訊
問題(Question):請問記憶體配置text, data, bss, heap, stack五個區塊中, C的結構structure是存在哪一個區塊呢? struct { int a; int array[100]; }TEST; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.238.1 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1454481810.A.73E.html
stupid0319: structure是一種概念,不存在於哪個區塊......... 02/03 14:55
※ 編輯: peng0116 (111.251.238.1), 02/03/2016 15:06:57
peng0116: 概念!?怎麼可能不存在記憶體區塊內...那變數存哪了... 02/03 15:11
stupid0319: 全域變數應當是放在data,區域變數在執行時會放stack 02/03 15:20
tjhuang: 確實 struct 的宣告不存在記憶體內,只是指示 offset 02/03 15:22
stupid0319: 至於struct是程式設計師的定義,此定義不存在於記憶體 02/03 15:23
dorgonman: TEST在這裡是放在data區 02/03 15:23
tjhuang: 例如你的 TEST.array 就只是標示 shift 4 bytes 02/03 15:23
dorgonman: https://en.wikipedia.org/wiki/Data_segment 02/03 15:23
peng0116: 了解,所以是看宣告struct TEST test;在全域還是區域 02/03 15:29
odanaga: 清大資工所 02/03 18:22
Caesar08: 樓上啥意思? 02/03 18:26
cobrasgo: 還要看前面有沒static 02/03 18:43
LPH66: 原 PO 你應該誤解了宣告...你原文裡的宣告 TEST 是變數名 02/03 18:55
LPH66: 跟著 struct 這個關鍵字後面的才是這 struct 的名字 02/03 18:55
LPH66: 所以像這個宣告是一個無名 struct, 然後宣告 TEST 為此型態 02/03 18:56
odanaga: 今年清大資工所出了這樣的題目 02/03 21:23
tinlans: 今年?所以題目還沒放上網嗎? 02/04 03:35
odanaga: B.html 02/05 17:32