我使用 QT 在 C++ 中为 Windows 创建了一个应用程序。如果我想将它移植到 Linux 或 Mac OS,sizeof(int)
或 sizeof(long)
会改变吗?换句话说,不同平台的QT应用程序中的类型是否具有相似的大小?
最佳答案
除了 stefaanv 的回答,如果你担心它们的大小,使用 quint32
和 friend 。 Qt 保证它们在所有支持的平台上大小相同。
查看 QtGlobal :
The header file declares several type definitions that guarantee a specified bit-size on all platforms supported by Qt for various basic types, for example qint8 which is a signed char guaranteed to be 8-bit on all platforms supported by Qt. The header file also declares the qlonglong type definition for long long int (__int64 on Windows).
Several convenience type definitions are declared: qreal for double, uchar for unsigned char, uint for unsigned int, ulong for unsigned long and ushort for unsigned short.
或者,如果您想要更标准的解决方案,可以使用 stdint.h .我一直喜欢使用 Qt,因为移植实际上只是在不同的平台上运行 qmake
。
关于c++ - 不同平台的 QT 应用程序中的类型是否具有相似的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1734026/