I am confused about the declaration of (for example) pid_t. What does __pid_t mean? Is it another type defined elsewhere? If yes, where? Why is my types.h in ubuntu 13.04 64bit defining pid_t like:
#ifndef __pid_t_defined
typedef __pid_t pid_t;
#define __pid_t_defined
#endif
and not something like
typedef int pid_t;
I saw some websites that have types.h headers with the declaration done the last way. This is one:
http://www.sde.cs.titech.ac.jp/~gondow/dwarf2-xml/HTML-rxref/app/gcc-3.3.2/lib/gcc-lib/sparc-sun-solaris2.8/3.3.2/include/sys/types.h.html
UPDATE:
Ok I found out that a pid_t is an __pid_t which is an __PID_T_TYPE which is which is an __S32_TYPE which is an int. My question now is why is this? POSIX only states that pid_t has to be a signed integer, so why make the declaration enter soo deep in header files?
If you are pulling up your types.h
via 'man types' then at the top of the header file(under description in the man page) there should exist an include file that defines '__pid_t'
at some point as a signed integer(if Ubuntu claims that their types are POSIX compliant; otherwise pid_t
could be anything). The symbol ' __'
is considered reserved(C standard, dunno about C++). If I had to take a wild guess as to why pid_t
is defined as __pid_t
and not some int is because __pid_t
is what Debian's or the Linux Kernel's developers decided to use for the process ID variable name in all of their library functions; therefore only '__pid_t'
needs to be changed to change the integer size for a process ID.
You should really look around before asking a question, similar stackoverflow questions are easily found: Size of pid_t, uid_t, gid_t on Linux .
Ok I found what the __pid_t means on the answer to this question:
Why PID of a process is represented by opaque data type?
QUOTE
typedef __pid_t pid_t;
...
# define __STD_TYPE typedef
__STD_TYPE __PID_T_TYPE __pid_t; /* Type of process identifications. */
...
#define __PID_T_TYPE __S32_TYPE
...
#define __S32_TYPE int
UNQUOTE
So pid_t is an __pid_t which is an __PID_T_TYPE which is which is an __S32_TYPE which is an int.