本文介绍了Linux中unistd.h和sys/types.h之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在The Open Group中搜索标题unistd.h时,发现它包含标准的符号常数&.类型和sys/types.h表示数据类型.

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.

然后我发现它们都具有uid_t,pid_t和几种类似的类型.

Then I found that both have uid_t, pid_t and several similar types.

我很困惑为什么他们如此分裂,以及它们之间有什么区别.我已经用谷歌搜索,但是没有得到满意的答案.

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.

谢谢.

推荐答案

细粒度文件中POSIX和C头文件的划分可能是由于过去编译可能需要很长时间,并且添加不必要的头文件使得时间更长.

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.

如果只需要OS类型,请说出功能的原型,然后只需 #include< sys/types.h> .但是,如果需要函数定义,则可以根据需要 #include< unistd.h> 或其他任何系统头文件.

If you only need the OS types, say for the prototypes of your functions, then just #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.

自然地,两个标头中都有类型,因为没有某些必要的类型就无法声明某些函数.

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.

这篇关于Linux中unistd.h和sys/types.h之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:40