Re: [問題] free記憶體後的問題
→
09/25 13:19,
09/25 13:19
哪本書寫的?
依照 C99 標準 7.20.3.4p2
The realloc function deallocates the old object pointed to by ptr and
returns a pointer to a new object that has the size specified by size.
...
If memory for the new object cannot be allocated, the old object is not
deallocated and its value is unchanged.
只有在無法配置空間時,realloc 才不會把舊有空間 free 掉。
→
09/25 13:20,
09/25 13:20
→
09/25 13:20,
09/25 13:20
這叫「未定義行為」,也就是任何結果都有可能
若要解釋為什麼舊的值還在,當然是可以解釋
但對你而言並沒有幫助,因為任何結果都可能發生
今天是程式正常結束,也許明天是程式當掉,後天是引爆核彈
初學者先學會避免未定義行為就好,不要花時間去研究未定義行為的現象
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.3.139
推
09/25 13:45, , 1F
09/25 13:45, 1F
推
09/25 20:46, , 2F
09/25 20:46, 2F
→
09/25 20:59, , 3F
09/25 20:59, 3F
討論串 (同標題文章)