How can adding a header increase portability? (sys/time.h)

前端 未结 2 1536
孤街浪徒
孤街浪徒 2021-01-22 03:34

I just noticed this line in the getrusage man page:

Including is not required these days, but increases portability. (Inde

相关标签:
2条回答
  • 2021-01-22 04:06

    In general, it was not uncommon in the early days of C for you to have to manually include header file A before header file B. Maybe an early version of the preprocessor couldn't do nested includes, or maybe it was just stylistic (manpages would often directly include the header files for relevant structures).

    "These days", sys/resource.h must either include sys/time.h or repeat the definition of struct timeval, but not every system follows the standard completely.

    0 讨论(0)
  • 2021-01-22 04:20

    It's because the BSD's require it:

    FreeBSD and OpenBSD need sys/time.h, not just time.h, before sys/resource.h.

    See this page on UNIX Portability for details.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题