C++ 中是否有实际的 8 位整数数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35246212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an actual 8-bit integer data type in C++
提问by tej-kweku
In c++, specifically the cstdint header file, there are types for 8-bit integers which turn out to be of the char data type with a typedef. Could anyone suggest an actual 8-bit integer type?
在 c++ 中,特别是 cstdint 头文件中,有一些 8 位整数类型,它们是带有 typedef 的 char 数据类型。谁能建议一个实际的 8 位整数类型?
回答by dlmeetei
Yes, you are right. int8_t
and uint8_t
are typedef
to char
on platforms where 1 byte is 8 bits. On platforms where it is not, appropriate definition will be given.
你是对的。int8_t
并且uint8_t
是typedef
到char
平台上,其中1个字节为8位。在没有它的平台上,将给出适当的定义。
Following answer is based on assumption that char is 8 bits
以下答案基于假设 char 是 8 bits
char
holds 1 byte, which may be signed
or unsigned
based on implementation.
char
持有 1 个字节,这可能是signed
或unsigned
基于实现。
So int8_t
is signed char
and uint8_t
is unsigned char
, but this will be safe to use int8_t/uint8_t as actual 8-bit integer without relying too much on the implementation.
所以,int8_t
是signed char
和uint8_t
是unsigned char
,但是这将是安全的使用中int8_t / uint8_t作为实际的8位整数,而不过分依赖于实现。
For a implementer's point of view, typedef
fing where char is 8 bits makes sense.
对于实现者的观点,typedef
fing 其中 char 是 8 位是有意义的。
Having seen all this, It is safe to use int8_t
or uint8_t
as real 8 bit integer.
看到这一切后,可以安全地使用int8_t
oruint8_t
作为真正的 8 位整数。