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

Tor Arne Vestbø Tor.arne.Vestbo at qt.io
Wed Sep 2 17:02:48 CEST 2020


> On 2 Sep 2020, at 16:49, Thiago Macieira <thiago.macieira at intel.com> wrote:
> 
> Tor Arne wrote:
>> As a user of this API I was also stumped by not being able to just call
>> printf with %z and a qsizetype, under the assumption that qsizetype’s
>> purpose in life was to mask _away_ the differences of what a size was
>> represented as.
> 
> For restricted scenarios (MSVC-only or Unix-only code), you can use those 
> modifiers. And in MSVC-only scenarios, there will be no type mismatch either, 
> in both 32- and 64-bit.
> 
> On 64-bit Unix, the result will be correct too, since the types are the right 
> size. The only thing is you may get a compiler warning that the types 
> mismatched. We could disable -Wformat.

Right, I was talking about the fact that even using %z will give you a warning, which seems counter to the assumed promise that qsizetype is a generic size type that masks away the platform differences. I’d expect one of the things it would do well, from an API/usability pov, is to be printable with the “size” format specifier 😊 

Today you need printf(“%z\n”, size_t(foo.size()));

Cheers,
Tor Arne






More information about the Development mailing list