Difference between unistd.h and sys/types.h in linux

本秂侑毒 提交于 2020-01-01 05:04:34

问题


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.

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.

Thank you.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/29984328/difference-between-unistd-h-and-sys-types-h-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!