您的位置:首页 > 产品设计 > UI/UE

关于int8_t,uint8_t.....等数据类型的问题

2017-07-30 19:06 1416 查看
最近在看代码的时候,发现好多师兄写的代码喜欢用下面一些数据类型:

typedef uint8_t     u8_t;
typedef int8_t      i8_t;
typedef uint16_t    u16_t;
typedef int16_t     i16_t;
typedef uint32_t    u32_t;
typedef int32_t     i32_t;
typedef uint64_t    u64_t;
typedef int64_t     i64_t;
typedef float       f32_t;
typedef double      f64_t;


然后让我写一个输出程序的时候,我就有些为难,用C的printf输出时这些32什么的占位符应该用什么呢,以前也没见过这种。

经过网上查找,发现这些都是已经被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)


注:此处参考博客C++下基本数据类型总结 (占位符 输入符 输出符)

so:

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据 class typedef