Posted on December 1st, 2009 at 13:37 by fr3@K
Very well put
當你發現回傳的是一個 char *,又沒有要求你特別 free 他,你是不是就該猜測他是回傳 function 內部的一個 static buffer 了呢?
![]() |
|
| Previous Post « What Happens When We Lie to the Compiler? « |
Next Post » Another Good Interview Question in C++ » |








Visual Studio 的骯髒解法是,針對這種 API,就 per thread 建立一個 buffer,指標存在 TLS (thread local storage) 裡,然後回傳之。
於是 upgrade visual studio 版本後,或是一開始就發現,程式很神奇的不會爛掉,但是當 porting 到其它「正常」的平台後,就爛掉了。
Comment by jeffhung — December 1, 2009 @ 14:41