实习中,今天在看公司源码的时候,发现前辈给的代码都是这样的
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef word_t word16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef dword_t dword32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef uint32 color_t;
typedef time_t time64;
typedef wchar_t char16;//宽字符
typedef char char8;
身为小白的我内心是这样的 ???????
查找后得出了结论,其实这些都是已经被typedef过的类型:
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
这些包含在inttypes.h头文件,据说这样做的原因是方便移植,比如int8就是8位大小占一字节,int32,,32位大小4字节…
这样相对应的占位符也就清楚了:
char /unsigned char: %c
int : %d
unsigned int: %u
long: %ld;
unsigned long:%lu
long long: %lld(%l64d)
unsigned long long:%Ilu(%l64u)
即:
int8_t:%c;
uint8_t:%c;
int16_t: %d;
uint16_t:%u;
int32_t:%ld;
uint32_t:%lu;
int64_t:%lld(%l64d);
uint64_t:%llu(%l64u);