There are some types in Qt, for example quint8 that is guaranteed to be 8-bit on all platforms supported by Qt.
I am wondering if C++11 has such kind of type? if not, what is the alternative for this?
Thanks.
Yes, C++11 adds types with more precisely defined sizes. Here's the reference.
They are defined in <cstdint>
.
You are guaranteed to have these:
intmax_t uintmax_t
int_least8_t uint_least8_t
int_least16_t uint_least16_t
int_least32_t uint_least32_t
int_least64_t uint_least64_t
int_fast8_t uint_fast8_t
int_fast16_t uint_fast16_t
int_fast32_t uint_fast32_t
int_fast64_t uint_fast64_t
You may or may not have these:
int8_t uint8_t
int16_t uint16_t
int32_t uint32_t
int64_t uint64_t
intptr_t uintptr_t
Explanations:
u
prefix means unsigned.least
variants are the smallest integer types available with at least that width.fast
variants are the fastest integer types available with at least that width.intptr
variants are guaranteed to be convertible to void*
and back.max
variants are the largest available types.Yes, it does, and even more. From the documentation:
uint8_t unsigned integer type with width of 8
uint_fast8_t fastest unsigned integer type with width of 8
uint_least8_t smallest unsigned integer type with width of at least 8
Disclaimer: this will not obviously work on platforms where Qt is supported and does not have C++11. If you plan to support those, stick with your quint8
, otherwise go drop it in favor of modern C++.
Make sure you will have this in your qmake project file to actually enable C++11:
CONFIG += c++11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With