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

Thiago Macieira thiago.macieira at intel.com
Tue Sep 1 16:23:50 CEST 2020


On Monday, 31 August 2020 04:55:32 PDT Giuseppe D'Angelo via Development 
wrote:
> Quick question (before Hyrum's law kicks in): qsizetype is currently
> defined as ptrdiff_t, but is it documented to be so?
> 
> For instance, is one supposed to print it in printf using %td?

It's always the same size as ptrdiff_t so you can cast to ptrdiff_t and never 
lose any data, before calling printf-like functions. In fact, it's defined to 
be a signed integer the same size as size_t, so the correct printf template is 
%zd, but that's being pedantic since ptrdiff_t is always the signed 
counterpart to size_t in all known platforms.

But it's not the same type as ptrdiff_t. The latter can assume one of three 
different types but qsizetype can only be two:

ptrdiff_t		qsizetype
int		int
long
long long		long long

So even if you use %td or %zd, GCC will complain in one of three different 
platform configurations (namely, 64-bit Unix).

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





More information about the Development mailing list