Exact width integers in C++/Qt: Is typedef int qint32 really correct?
Qt文档说:
typedef qint8
Typedef for signed char. This type is guaranteed to be 8-bit on all platforms supported by Qt.
typedef qint16
Typedef for signed short. This type is guaranteed to be 16-bit on all platforms supported by Qt.
typedef qint32
Typedef for signed int. This type is guaranteed to be 32-bit on all platforms supported by Qt.
typedef qint64
Typedef for long long int (__int64 on Windows). This type is guaranteed to be 64-bit on all platforms supported by Qt.
在
1 2 3 4 5 6 7 8 9 10 11 | /* Size-dependent types (architechture-dependent byte order) Make sure to update QMetaType when changing these typedefs */ typedef signed char qint8; /* 8 bit signed */ typedef unsigned char quint8; /* 8 bit unsigned */ typedef short qint16; /* 16 bit signed */ typedef unsigned short quint16; /* 16 bit unsigned */ typedef int qint32; /* 32 bit signed */ typedef unsigned int quint32; /* 32 bit unsigned */ //.... |
但是我想知道,如果不能保证据我所知,在64位体系结构上,
如何保证尺寸?他们为什么不使用
How can they guarantee the sizes?
他们以他们知道上述定义有效的特定平台为目标。 Qt不在乎其他平台,其他平台也不在乎Qt。因此,它并不总是有效。但是在无法正常工作的地方,Qt。
Why don't they use stdint (and __intN on windows platforms)?
有时候,为自己的项目在
Qt支持许多平台,但重要的是该平台的64位数据模型(或更正确地说,是编译器加平台的数据模型)。??
大多数常见的64位平台使用32位整数,因为它们实现某种形式的LP64数据模型。基于ILP64的数据模型(ILP64,SILP64等)将整数定义为64位。但是我不相信Qt支持任何这些平台。
查看ILP64 Wiki页面以及此PVS-Studio支持页面,其中包含一些良好的技术信息。