根據該男子頁getaddrinfo(3)
,我需要爲什麼包含一個POSIX函數的多個頭文件?
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
使用的功能getaddrinfo
。或者,根據the standard:
#include <sys/socket.h>
#include <netdb.h>
我明白我需要的東西像<sys/socket.h>
AF_INET
和SOCK_STEAM
。但我仍然有以下問題。
假設我將只使用getaddrinfo
函數,我必須要#include <sys/socket.h>
是標準符合嗎?如果是這樣,爲什麼不<netdb.h>
包括它本身?如果沒有,爲什麼手冊頁將它包含在大綱中?
在舊版本的POSIX(那些來自上一個千年,而不是這個),''大多數地方需要。 POSIX 2004升級了一些東西,所以你很少或永遠不需要再包含它。這是'殘酷',但它有一個歷史性的理由。 –
@JonathanLeffler:你有這個引用嗎? –
例如:['getgid()'1997](http://pubs.opengroup.org/onlinepubs/7990989775/xsh/getgid.html); ['getgid()'2004](http://pubs.opengroup.org/onlinepubs/009695399/functions/getgid.html)。可能有某處指明它的地方 - 我最近沒有找過它。 –