diff options
Diffstat (limited to 'src/corelib/global/qtypes.cpp')
-rw-r--r-- | src/corelib/global/qtypes.cpp | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/src/corelib/global/qtypes.cpp b/src/corelib/global/qtypes.cpp index 8441b9806b..9de3960e2f 100644 --- a/src/corelib/global/qtypes.cpp +++ b/src/corelib/global/qtypes.cpp @@ -15,6 +15,31 @@ QT_BEGIN_NAMESPACE /*! + \headerfile <QtTypes> + \inmodule QtCore + \title Qt Type Declarations + + \brief The <QtTypes> header file includes Qt fundamental type declarations. + + 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 \l qint8 which is a signed char + guaranteed to be 8-bit on all platforms supported by Qt. The + header file also declares the \l qlonglong type definition for + \c {long long int}. + + Several convenience type definitions are declared: \l qreal for \c + double or \c float, \l uchar for \c {unsigned char}, \l uint for + \c {unsigned int}, \l ulong for \c {unsigned long} and \l ushort + for \c {unsigned short}. + + The header also provides series of macros that make it possible to print + some Qt type aliases (qsizetype, qintptr, etc.) via a formatted output + facility such as printf() or qDebug() without raising formatting warnings + and without the need of a type cast. +*/ + +/*! \typedef qreal \relates <QtTypes> @@ -120,6 +145,43 @@ QT_BEGIN_NAMESPACE */ /*! + \typedef qint128 + \relates <QtTypes> + \since 6.6 + + Typedef for \c{__int128} on platforms that support it (Qt defines the macro + \l QT_SUPPORTS_INT128 if this is the case). + + Literals of this type can be created using the Q_INT128_C() macro. + + \sa Q_INT128_C(), Q_INT128_MIN, Q_INT128_MAX, quint128, QT_SUPPORTS_INT128 +*/ + +/*! + \typedef quint128 + \relates <QtTypes> + \since 6.6 + + Typedef for \c{unsigned __int128} on platforms that support it (Qt defines + the macro \l QT_SUPPORTS_INT128 if this is the case). + + Literals of this type can be created using the Q_UINT128_C() macro. + + \sa Q_UINT128_C(), Q_UINT128_MAX, qint128, QT_SUPPORTS_INT128 +*/ + +/*! + \macro QT_SUPPORTS_INT128 + \relates <QtTypes> + \since 6.6 + + Qt defines this macro as well as the \l qint128 and \l quint128 types if + the platform has support for 128-bit integer types. + + \sa qint128, quint128, Q_INT128_C(), Q_UINT128_C(), Q_INT128_MIN, Q_INT128_MAX, Q_UINT128_MAX +*/ + +/*! \typedef qintptr \relates <QtTypes> @@ -148,6 +210,25 @@ QT_BEGIN_NAMESPACE \sa qptrdiff, qint32, qint64 */ +/*! \typedef qlonglong + \relates <QtTypes> + + Typedef for \c{long long int} (\c __int64 on Windows). This is + the same as \l qint64. + + \sa qulonglong, qint64 +*/ + +/*! + \typedef qulonglong + \relates <QtTypes> + + Typedef for \c{unsigned long long int} (\c{unsigned __int64} on + Windows). This is the same as \l quint64. + + \sa quint64, qlonglong +*/ + /*! \macro PRIdQINTPTR \macro PRIiQINTPTR @@ -273,6 +354,104 @@ QT_BEGIN_NAMESPACE See qsizetype. */ +/*! \macro qint64 Q_INT64_C(literal) + \relates <QtTypes> + + Wraps the signed 64-bit integer \a literal in a + platform-independent way. + + Example: + + \snippet code/src_corelib_global_qglobal.cpp 8 + + \sa qint64, Q_UINT64_C(), Q_INT128_C() +*/ + +/*! \macro quint64 Q_UINT64_C(literal) + \relates <QtTypes> + + Wraps the unsigned 64-bit integer \a literal in a + platform-independent way. + + Example: + + \snippet code/src_corelib_global_qglobal.cpp 9 + + \sa quint64, Q_INT64_C(), Q_UINT128_C() +*/ + +/*! + \macro qint128 Q_INT128_C(literal) + \relates <QtTypes> + \since 6.6 + + Wraps the signed 128-bit integer \a literal in a + platform-independent way. + + \note Unlike Q_INT64_C(), this macro is only available in C++, not in C. + This is because compilers do not provide these literals as built-ins and C + does not have support for user-defined literals. + + \sa qint128, Q_UINT128_C(), Q_INT128_MIN, Q_INT128_MAX, Q_INT64_C(), QT_SUPPORTS_INT128 +*/ + +/*! + \macro quint128 Q_UINT128_C(literal) + \relates <QtTypes> + \since 6.6 + + Wraps the unsigned 128-bit integer \a literal in a + platform-independent way. + + \note Unlike Q_UINT64_C(), this macro is only available in C++, not in C. + This is because compilers do not provide these literals as built-ins and C + does not have support for user-defined literals. + + \sa quint128, Q_INT128_C(), Q_UINT128_MAX, Q_UINT64_C(), QT_SUPPORTS_INT128 +*/ + +/*! + \macro Q_UINT128_MAX + \relates <QtTypes> + \since 6.6 + + This macro expands to a compile-time constant representing the + maximum value representable in a \l quint128. + + This macro is available in both C++ and C modes. + + The minimum of \l quint128 is 0 (zero), so a \c{Q_UINT128_MIN} is neither + needed nor provided. + + \sa Q_INT128_MAX, quint128, Q_UINT128_C, QT_SUPPORTS_INT128 +*/ + +/*! + \macro Q_INT128_MIN + \relates <QtTypes> + \since 6.6 + + This macro expands to a compile-time constant representing the + minimum value representable in a \l qint128. + + This macro is available in both C++ and C modes. + + \sa Q_INT128_MAX, qint128, Q_INT128_C, QT_SUPPORTS_INT128 +*/ + +/*! + \macro Q_INT128_MAX + \relates <QtTypes> + \since 6.6 + + This macro expands to a compile-time constant representing the + maximum value representable in a \l qint128. + + This macro is available in both C++ and C modes. + + \sa Q_INT128_MIN, Q_UINT128_MAX, qint128, Q_INT128_C, QT_SUPPORTS_INT128 +*/ + // Statically check assumptions about the environment we're running // in. The idea here is to error or warn if otherwise implicit Qt // assumptions are not fulfilled on new hardware or compilers @@ -322,11 +501,28 @@ static_assert(std::numeric_limits<float>::radix == 2, static_assert(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size"); static_assert(sizeof(size_t) == sizeof(qsizetype)); // implied by the definition static_assert((std::is_same<qsizetype, qptrdiff>::value)); +static_assert(std::is_same_v<std::size_t, size_t>); // Check that our own typedefs are not broken. static_assert(sizeof(qint8) == 1, "Internal error, qint8 is misdefined"); static_assert(sizeof(qint16)== 2, "Internal error, qint16 is misdefined"); static_assert(sizeof(qint32) == 4, "Internal error, qint32 is misdefined"); static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined"); +#ifdef QT_SUPPORTS_INT128 +static_assert(sizeof(qint128) == 16, "Internal error, qint128 is misdefined"); +#endif + +#ifdef QT_SUPPORTS_INT128 +// Standard Library supports for 128-bit integers: +// Implementation | Version | Note +// ---------------------|---------|------ +// GNU libstdc++ | 11.1.0 | +// LLVM libc++ | 3.5 | May change if compiler has __is_integral() +// MS STL | none | + +# if defined(_LIBCPP_VERSION) || (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 11) +static_assert(std::numeric_limits<quint128>::max() == Q_UINT128_MAX); +# endif +#endif QT_END_NAMESPACE |