什么是int8_t如果机器有> 8位/字节? [英] What is int8_t if a machine has > 8 bits per byte?

查看:148
本文介绍了什么是int8_t如果机器有> 8位/字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读 C ++常见问题,并说


C ++语言保证一个字节必须至少有8位


那么,< cstdint> 类型是什么意思?



我应该使用 int8_t char 为什么?

intX_t (即确切的宽度整数类型)typedefs作为可选



如果你想要一个字节数组,你应该使用 char sizeof char (和 signed char unsigned char )定义为总是1个字节。


I was reading the C++ FAQ and it says

The C++ language guarantees a byte must always have at least 8 bits

So what does that mean for the <cstdint> types?

Side question - if I want an array of bytes should I use int8_t or char and why?

解决方案

C++ (and C as well) defines intX_t (i.e. the exact width integer types) typedefs as optional. So, it just won't be there if there is no addressable unit that's exactly 8-bit wide.

If you want an array of bytes, you should use char, as sizeof char (and signed char and unsigned char) is well-defined to always be 1 byte.

这篇关于什么是int8_t如果机器有&gt; 8位/字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆