如何添加标头可提高可移植性? (sys/time.h) [英] How can adding a header increase portability? (sys/time.h)

查看:121
本文介绍了如何添加标头可提高可移植性? (sys/time.h)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 getrusage 手册页中注意到了这一行:

I just noticed this line in the getrusage man page:

这些天不需要

包含<sys/time.h>,但是可以提高可移植性. (实际上,struct timeval是在<sys/time.h>中定义的)

Including <sys/time.h> is not required these days, but increases portability. (Indeed, struct timeval is defined in <sys/time.h>)

什么?由于struct rusage包含struct timeval作为成员,因此肯定sys/resource.h必须包含sys/time.h,否则类型将不完整且无法使用?

What? Since struct rusage contains struct timeval as a member, surely sys/resource.h must include sys/time.h or the type would be incomplete and unusable?

此评论怎么可能有意义?怎么可能没有必要呢?曾经如何帮助可移植性?

How could this comment ever have made sense? How could it ever have not been necessary? How could portability have ever been helped?

推荐答案

通常,在C的早期,您不得不在头文件B之前手动包括头文件A的情况并不少见.预处理器无法嵌套包含,或者仅仅是样式(联机帮助页通常会直接包含相关结构的头文件).

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).

这些天",sys/resource.h必须包含sys/time.h或重复struct timeval的定义,但并非每个系统都完全遵循该标准.

"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.

这篇关于如何添加标头可提高可移植性? (sys/time.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆