Home Ask Login Register

Developers Planet

Your answer is one click away!

tej-kweku February 2016

Is there an actual 8-bit integer data type in C++

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?

Answers


dlmeetei February 2016

Yes, you are right. int8_t and uint8_t are typedef to char on platforms where 1 byte is 8 bits. In 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 with relying too much on the implementation.

For a implementer's point of view, typedeffing 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.

Post Status

Asked in February 2016
Viewed 2,295 times
Voted 11
Answered 1 times

Search




Leave an answer


Quote of the day: live life