Reputation: 433
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?
Upvotes: 32
Views: 95103
Reputation: 149
There are __int8
, __int16
, __int32
, __int64
default data type (this also
applied for C programming language), without using the <cstdint>
header and there aren't __int128
for Microsoft-specific (lot of answers is at here, and even intrinsic function __shiftleft128
, __shiftright128
use two __int64
for example).
int8_t
is char
are also applied for unsigned types, for example, uint8_t
are unsigned char
.
Upvotes: 1
Reputation: 10391
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.
Following answer is based on assumption that char is 8 bits
char
holds 1 byte, which may be signed
or unsigned
based on implementation.
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.
For a implementer's point of view, typedef
fing where char is 8 bits makes sense.
Having seen all this, It is safe to use int8_t
or uint8_t
as real 8 bit integer.
Upvotes: 39