作者ric2k1 (Ric)
看板EE_DSnP
標題Re: [問題] hw1.2.p1b(iv)
時間Sat Oct 5 22:51:17 2013
: --
:
※ 發信站: 批踢踢實業坊(ptt.cc)
: ◆ From: 111.248.105.212
: 推 nianze:請問為甚麼P1a的大小是16bytes?我用sizeof(P1a)得到8bytes 10/05 17:23
: → nianze:而且string+int=8bytes好像很合理?請老師再多解釋一點謝謝 10/05 17:25
哦,P1a 的 size 應該是 platform independent.
"string" 在 32 & 64 bit machine 的 size 分別為 4 & 8 Bytes,
所以在 32 bit machine 是 8 Bytes 無誤,
但在 64-bit machine 由於 memory allignment 的關係,
會在 int _dummy 與 string _str 之間塞入 4 Bytes,
讓總 size 變成 16 Bytes.
: 推 nianze:另外,既然arr1b_3[i]是P1a*,那derefernce後不就是P1a了嗎 10/05 17:28
不確定你為什麼要 dereference...
The content of arr1b_3[i] 就直接 "cout << arr1b_3[i]" 就好了,
所以印出來的是一個 memory address 指向存 P1a 的 memory.
如果你 dereference 再印,像是 "cout << *(arr1b)3[i]",
compiler 應該會 complain "operator << (...)" not defined 吧!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.248.105.212
※ 編輯: ric2k1 來自: 111.248.105.212 (10/05 22:52)
1F:→ ric2k1:上次下課有人來問我 string 的 size,我跟他講錯了! 10/05 22:53
2F:推 nianze:我是想要確定arr1b_3[i]指向的東西的大小是多少 原本以為 10/05 22:58
3F:→ nianze:變成16bytes 和題目要求無關 謝謝老師解答! 10/05 22:59