Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does c++11 have something like quint8? [duplicate]

Tags:

c++

c++11

qt

qtcore

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.

like image 365
camino Avatar asked Jun 11 '14 18:06

camino


2 Answers

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:

  • The u prefix means unsigned.
  • The least variants are the smallest integer types available with at least that width.
  • The fast variants are the fastest integer types available with at least that width.
  • The intptr variants are guaranteed to be convertible to void* and back.
  • The max variants are the largest available types.
like image 59
Lstor Avatar answered Sep 19 '22 23:09

Lstor


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
like image 41
lpapp Avatar answered Sep 18 '22 23:09

lpapp