Linux中 pid_t 類型的定義.


說明:涉及到的頭文件(.h),目錄默認都是基於 /usr/include/ 目錄.

1.在 "/sys/types.h"中,有下列內容:

1 #include <bits/types.h>
2 #ifndef __pid_t_defined
3 100 typedef __pid_t pid_t;
4 101 # define __pid_t_defined
5 102 #endif

很明顯, pid_t 只是 __pid_t 的別名.或者說, pid_t 類型其實是 __pid_t 類型.

2.在"bits/types.h"中,有下列內容:

1 /* We want __extension__ before typedef's that use nonstandard base types
2 118    such as `long long' in C89 mode.  */
3 119 # define __STD_TYPE             __extension__ typedef
4 120 #elif __WORDSIZE == 64
5 ...
6 #include <bits/typesizes.h>     /* Defines __*_T_TYPE macros.  */
7 __STD_TYPE __PID_T_TYPE __pid_t;        /* Type of process identifications.
8  */

由第一行和第二行的注釋中,我們可以忽略 __extension__ 的分析.故 __STD_TYPE 表示 typedef.所以在第七行的代碼中,可以知道:

__pid_t 類型 其實是 __PID_T_TYPE 類型.

3.在 "bits/typesizes.h" 中,有以下內容:

1 /* See <bits/types.h> for the meaning of these macros.  This file exists so
2  28    that <bits/types.h> need not vary across different GNU platforms.  */
3 
4 ...
5 #define __PID_T_TYPE            __S32_TYPE

由此我們知道 __PID_T_TYPE 就是 __S32_TYPE 類型.並且這個文件沒有引用任何其他的頭文件.

4.在 "bits/types.h" 文件中,我們看到有以下內容:

1 #define __S32_TYPE              int

由此,最終可以知道,__S32_TYPE 就是 int 類型,也就是說, pid_t  其實就是 int 類型.

引自:  http://doudouclever.blog.163.com/blog/static/17511231020112248130302/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM