Is int a guarantee to be 32 bits on every platform supported by Qt, or only qint32?

I remember reading somewhere that Qt guarantees the size of some data types on supported platforms. Is there intat least 32 bits everywhere, and there qint32will be exactly 32 bits all over the world? Or something else?

C ++ guarantees that there intwill be at least 16 bits, and some Qt structures, such as QRectand QPoint, are used intinternally. I am developing an application that requires 32 bits with these types, and I do not want to duplicate their functionality, so I can use a larger type.

+5
source share
2 answers

The size of the integer type depends on the compiler. I do not think that there is a guarantee that the regular one intwill have the exact size. But you can make sure that you know this is not what you want by adding this line at the beginning of yours main():

if(sizeof(int) != 4) {
  throw std::runtime_error("int is not 32-bit");
}
+6
source

Although, as far as I know, it is technically possible that int is not 32 bits, I have never seen a platform where it is not. Imagine-char, 8bit, short, 16bit, int, .. 24bit? It just doesn't match the hierarchy for int not 32 bits.

Alternatively, you can use UINT_MAX to confirm the size of an int on your compiler.

0
source

All Articles