什么是int8_t如果机器有> 8位/字节? [英] What is int8_t if a machine has > 8 bits per byte?
问题描述
我在阅读 C ++常见问题,并说
C ++语言保证一个字节必须至少有8位
那么,< cstdint>
类型是什么意思?
我应该使用 int8_t
或 char
为什么?
如果你想要一个字节数组,你应该使用 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如果机器有> 8位/字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!