[Development] Is qsizetype *documented* to be ptrdiff_t?

Thiago Macieira thiago.macieira at intel.com
Tue Sep 1 19:29:24 CEST 2020

On Tuesday, 1 September 2020 08:44:07 PDT Giuseppe D'Angelo via Development 
> Il 01/09/20 16:23, Thiago Macieira ha scritto:
> > So even if you use %td or %zd, GCC will complain in one of three different
> > platform configurations (namely, 64-bit Unix).
> Pedantically, do we need the PRIxQSS (?) macro and friends to use
> qsizetype into qWarning etc.?

That's ugly. Just cast the type itself to ptrdiff_t or int.

That is, write:

    qWarning("List too big: %zd", ptrdiff_t(list.size());

Qt's internal sprintf-like functions actually use qsizetype, not ptrdiff_t, so 
pedantically-strictly speaking the compiler is wrong and your code was right 
without the cast. In real-life, it just works.

Note: this only applies to the functions that actually use Qt's own sprintf-
like functions. You can't use with printf family itself because we still 
support MinGW and that one uses a C99-incompatible standard library by default 
(no "z" and no "t" modifier and no 64-bit support on 32-bit systems).

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering

More information about the Development mailing list