[問題] 關於dlsym()這個函數的問題

看板LinuxDev作者 (我是青蛙,不是王子^_^)時間13年前 (2011/08/15 22:40), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
大家好,關於dlsym()這個函數,在網路上有看到一段解釋如下 dlsym() will return a NULL result if the symbol wasn't found. If you know that the symbol could never have the value of NULL or zero, that may be fine, but there's a potential ambiguity otherwise: if you got a NULL, does that mean there is no such symbol, or that NULL is the value of the symbol? The standard solution is to call dlerror() first (to clear any error condition that may have existed), then call dlsym() to request a symbol, then call dlerror() again to see if an error occurred. 中間有一段話 (抱歉不會上色,所以另外標出來) : if you got a NULL, does that mean there is no such symbol, or that NULL is the value of the symbol? 假設這個symbol是一個函數,會發生symbol成功取得,但是卻指向NULL的情況嗎? 想像不太出來這到底是什麼狀況,能否舉個例子讓小弟了解 謝謝大家的回答。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.230.2

08/15 23:13, , 1F
他是回傳SO裏頭每個變數的值, 如果該值為0,回傳當然為0
08/15 23:13, 1F

08/15 23:14, , 2F
如果找不到該值, 將會回傳0 (NULL)
08/15 23:14, 2F

08/17 22:45, , 3F
腦袋打結挺嚴重的,謝謝你的回答XD
08/17 22:45, 3F
文章代碼(AID): #1EII_mo1 (LinuxDev)