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

最近在看代码的时候,发现好多师兄写的代码喜欢用下面一些数据类型:

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);
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值