简体   繁体   English

linux中的unistd.h和sys / types.h之间的区别

[英]Difference between unistd.h and sys/types.h in linux

When I have searched for the header unistd.h, in The Open Group, I found that it contains the standard symbolic constants & types and for sys/types.h it said for data types. 当我搜索头文件unistd.h时,在Open Group中,我发现它包含标准的符号常量和类型,而对于sys / types.h,它表示数据类型。

Then I found that both have uid_t, pid_t and several similar types. 然后我发现它们都有uid_t,pid_t和几种类似的类型。

I am confused why they have divided so and what are the differences between them. 我很困惑为什么他们分开了,他们之间有什么区别。 I have googled but I didn't get a satisfactory answers. 我用谷歌搜索,但我没有得到满意的答案。

I will be thankful if some one can give me detailed explanation. 如果有人能给我详细解释,我将感激不尽。

Thank you. 谢谢。

The division of the POSIX and C header in fine grained files probably comes from the old days when compilation might take a long time, and adding unnecesary header files made the time longer. 细粒度文件中POSIX和C头的划分可能来自于编译可能需要很长时间的旧时代,并且添加不必要的头文件会使时间更长。

If you only need the OS types, say for the prototypes of your functions, then just #include <sys/types.h> . 如果您只需要操作系统类型,比如函数的原型,那么只需#include <sys/types.h> However if you need the function definitions, then you #include <unistd.h> or any of the other system headers, as needed. 但是,如果需要函数定义,则根据需要#include <unistd.h>或任何其他系统头。

Naturally there are types that are in both headers, as you cannot declare some functions without their necessary types. 当然,两个标题中都有类型,因为如果没有必要的类型,就无法声明某些函数。

But these different declarations of the same type are guaranteed to be the same, so there is no problem if you include both. 但是这些相同类型的不同声明保证是相同的,因此如果包含两者,则没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM