分类: LINUX
2011-12-26 12:10:13
++++++APUE读书笔记-02UNIX标准和实现-08系统基本类型++++++
8、系统基本数据类型
================================================
以前,特定的C数据类型和特定的UNIX系统变量相关联。例如,设备的主设备号和次设备号码以前存放在一个16位的短整数类型中,其中的8位用于主设备号码,另外的8位用于次设备号码。但是,许多大的系统中,设备号码的值会多于256个,所以需要一种特定的技术(实际上,solaris使用32位表示设备号码:14位用于主设备号,18位用于次设备号)。
头文件
一些通用的系统原始数据类型
+-------------------------------------------------------------------------------------------+
| Type | Description |
|--------------+----------------------------------------------------------------------------|
| caddr_t | core address (Section 14.9) |
|--------------+----------------------------------------------------------------------------|
| clock_t | counter of clock ticks (process time) (Section 1.10) |
|--------------+----------------------------------------------------------------------------|
| comp_t | compressed clock ticks (Section 8.14) |
|--------------+----------------------------------------------------------------------------|
| dev_t | device numbers (major and minor) (Section 4.23) |
|--------------+----------------------------------------------------------------------------|
| fd_set | file descriptor sets (Section 14.5.1) |
|--------------+----------------------------------------------------------------------------|
| fpos_t | file position (Section 5.10) |
|--------------+----------------------------------------------------------------------------|
| gid_t | numeric group IDs |
|--------------+----------------------------------------------------------------------------|
| ino_t | i-node numbers (Section 4.14) |
|--------------+----------------------------------------------------------------------------|
| mode_t | file type, file creation mode (Section 4.5) |
|--------------+----------------------------------------------------------------------------|
| nlink_t | link counts for directory entries (Section 4.14) |
|--------------+----------------------------------------------------------------------------|
| off_t | file sizes and offsets (signed) (lseek, Section 3.6) |
|--------------+----------------------------------------------------------------------------|
| pid_t | process IDs and process group IDs (signed) (Sections 8.2 and 9.4) |
|--------------+----------------------------------------------------------------------------|
| ptrdiff_t | result of subtracting two pointers (signed) |
|--------------+----------------------------------------------------------------------------|
| rlim_t | resource limits (Section 7.11) |
|--------------+----------------------------------------------------------------------------|
| sig_atomic_t | data type that can be accessed atomically (Section 10.15) |
|--------------+----------------------------------------------------------------------------|
| sigset_t | signal set (Section 10.11) |
|--------------+----------------------------------------------------------------------------|
| size_t | sizes of objects (such as strings) (unsigned) (Section 3.7) |
|--------------+----------------------------------------------------------------------------|
| ssize_t | functions that return a count of bytes (signed) (read, write, Section 3.7) |
|--------------+----------------------------------------------------------------------------|
| time_t | counter of seconds of calendar time (Section 1.10) |
|--------------+----------------------------------------------------------------------------|
| uid_t | numeric user IDs |
|--------------+----------------------------------------------------------------------------|
| wchar_t | can represent all distinct character codes |
+-------------------------------------------------------------------------------------------+
通过用这种方式来定义这些数据类型,我们就不用由于各种系统的不同,而向我们的应用程序中加入和实现细节相关的东西,进行编译。我们在本书后面遇到这些数据类型的时候,将会讲述每种数据类型的作用。
参考: