Difference between unistd.h and sys/types.h in linux
Asked Answered
T

1

9

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.

Toluate answered 1/5, 2015 at 9:18 Comment(0)
M
12

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.

Marmalade answered 1/5, 2015 at 9:59 Comment(1)
hmmm ...... I didn't think about that: function definitions in unistd.h will mess things, which will consume time at compilation time. I got an idea about it now. Thank you.Toluate

© 2022 - 2024 — McMap. All rights reserved.