qt6-bb10/tests/auto/corelib/global
Giuseppe D'Angelo 5fabad9a61 Long live PRI*Qdatatypes
Qt defines some integral datatypes (qsizetype, qintptr, quintptr,
qptrdiff) not in terms of the corresponding language datatypes (resp.
make_signed_t<size_t>, intptr_t, uintptr_t, ptrdiff_t) but as "integer
types with the same bit size of the corresponding language type" (and of
course the corret correct signedness for the target type).

This makes the Qt datatypes not printable via printf-like formatted
output, incl. qDebug, qWarning, QString::asprintf and so on; that's
because there isn't a format modifier that would universally work
with the Qt definitions.

For instance, on a 32 bit platform, ptrdiff_t may be a typedef for long,
while qptrdiff is a typedef for _int_ instead. Both long and int would
indeed be 32 bits, but they still are different types, and this means
that the ptrdiff_t-specific 't' length modifier would be wrong for
qptrdiff:

  qptrdiff p;
  printf("%td", p); // WARNING: -Wformat: wanted long, got int

Similarly, not using 't' breaks on 64 bits, and so on and so forth.
There isn't a way out, short of inserting casts on every print
statement.

So, let's adopt the same solution C/C++ use for their own integer
typedefs: the PRIx macros. This allows one to always use the correct
formatting specifier without the need of a cast.

I'm not adding the macros for the qintXX datatypes, as they already
exist in the Standard Library.

[ChangeLog][QtCore][QtGlobal] A series of PRIxQTDATATYPE macros have
been added. They 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.

Change-Id: I473226a661868aed9514d793c8e6e4d391ab5055
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-04-25 15:24:45 +02:00
..
q_func_info Remove the qmake project files 2021-01-07 15:32:28 +01:00
qcompare Remove the qmake project files 2021-01-07 15:32:28 +01:00
qflags Remove the qmake project files 2021-01-07 15:32:28 +01:00
qfloat16 Remove the qmake project files 2021-01-07 15:32:28 +01:00
qgetputenv Remove the qmake project files 2021-01-07 15:32:28 +01:00
qglobal Long live PRI*Qdatatypes 2021-04-25 15:24:45 +02:00
qglobalstatic Skip globalstatic threadStressTest on QEMU 2021-03-05 08:09:59 +00:00
qhooks Remove the qmake project files 2021-01-07 15:32:28 +01:00
qkeycombination Remove the qmake project files 2021-01-07 15:32:28 +01:00
qlogging CMake: Build minimal subset of tests in desktop static builds 2021-04-06 09:15:37 +01:00
qnumeric Remove the qmake project files 2021-01-07 15:32:28 +01:00
qoperatingsystemversion Remove the qmake project files 2021-01-07 15:32:28 +01:00
qrandomgenerator Remove the qmake project files 2021-01-07 15:32:28 +01:00
qtendian Remove the qmake project files 2021-01-07 15:32:28 +01:00
qwinregistry Remove the qmake project files 2021-01-07 15:32:28 +01:00
CMakeLists.txt Fix QVariant/QMetaType::compare APIs 2020-11-30 17:16:22 +01:00