看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) GNU GCC/G++ 問題(Question): 今天看朋友的程式 才知道有 hstrerror 這個函式, 而我朋友傳入 h_errno 給他 不過 man page 寫的讓我很困惑, The (obsolete) hstrerror() function takes an error number (typically h_errno) and returns the corresponding message string. 這邊的 obsolete 到底是指什麼呢? http://ftp.suacommunity.com/man/3/strerror.3.html 然後這裡寫的更讓我困惑@@ The hstrerror(3) call is a #define for strerror(3), provided for convenience in working with sockets. 所以這兩個根本沒有差嗎? 可是好像 h_errno, errno 是不同變數, hstrerror 跟 strerror 也是不同函數. 所以這兩個函數有差嗎? 印 socket 相關的錯誤訊息 (如 gethostbyname 錯誤) 應該使用 hstrerror 嗎? man page 裡面又寫 RETURN VALUE The gethostbyname() and gethostbyaddr() functions return the hos- tent structure or a NULL pointer if an error occurs. On error, the h_errno variable holds an error number. When non-NULL, the return value may point at static data, see the notes below. 所以我使用 errno 就夠了? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.45.226
tomnelson:文件寫得很清楚,hstrerror()只是一個使用#define去轉呼 12/01 14:03
tomnelson:叫strerror的macro而已,而你問的"obsolete"是指現在來說 12/01 14:06
tomnelson:hstrerror這個function已經不建議用了. 為什麼會用macro 12/01 14:06
tomnelson:define的方式把hstrerror轉呼叫到strerror呢? 你好好想 12/01 14:07
tomnelson:想,其實這是為了讓一些舊的程式是使用hstrerror的,能夠 12/01 14:08
tomnelson:在不改原始碼的情況下,能夠被compile成功. 總而言之, 這 12/01 14:09
tomnelson:個hstrerror算是有歷史的東西,但後來處理error number的 12/01 14:10
tomnelson:部份就統一用strerror了,hstrerror前面的"h"其實可能在 12/01 14:10
tomnelson:當時是for hostxxx相關的function用的. 所以用errno 和 12/01 14:12
tomnelson:strerror就好了! 12/01 14:12
suhorng:了解了, 謝謝你! 12/01 18:31
suhorng:因為我在我裝的 include 檔中, hstrerror 宣告成 extern, 12/01 18:42
suhorng:印出來也跟 strerror 不同位置, 所以很困惑 12/01 18:42
MOONRAKER:obsolete == 「過時」 比 deprecated 更過時 12/02 09:53