typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef uint8_t u8;
typedef uint16_ u16;
typedef uint32_t u32;
1 size_t
size_t 是C+标准在stddef.h中定义的。这个类型足以用来表示对象的大小。size_t的真实类型与操作系统有关。size_t在32位架构上是4字节,在64位架构上是8字节,在不同架构上进行编译时需要注意这个问题。而int在不同架构下都是4字节,与size_t不同;且int为带符号数,size_t为无符号数。
在32位架构中被普遍定义为: | typedef unsigned int size_t; |
而在64位架构中被定义为: | typedef unsigned long size_t; |
2 ssize_t
ssize_t是有符号整型,在32位机器上等同与int,在64位机器上等同与long int
在32位架构中被普遍定义为: | typedef int size_t; |
而在64位架构中被定义为: | typedef long size_t; |
3 size_t 与 ssize_t 的作用
size_t一般用来表示一种计数,比如有多少东西被拷贝等。例如:sizeof操作符的结果类型是size_t,该类型保证能容纳实现所建立的最大对象的字节大小。 它的意义大致是“适于计量内存中可容纳的数据项目个数的无符号整数类型”。所以,它在数组下标和内存管理函数之类的地方广泛使用。
而ssize_t这个数据类型用来表示可以被执行读写操作的数据块的大小.它和size_t类似,但必需是signed.意即:它表示的是signed size_t类型的。
C语言常用头文件:
#ifndef _Includes_H_
#define _Includes_H_
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <string>
#endif