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

Lars Knoll lars.knoll at qt.io
Thu Sep 3 08:54:35 CEST 2020



> On 3 Sep 2020, at 07:06, Thiago Macieira <thiago.macieira at intel.com> wrote:
> 
> On Wednesday, 2 September 2020 21:37:23 PDT Giuseppe D'Angelo via Development 
> wrote:
>> On 03/09/2020 06:08, Thiago Macieira wrote:
>>> Because qsizetype is the same type as qint64, which is the same type as
>>> qlonglong (which exists for historical reasons, because older VC++ didn't
>>> support "long long").
>> 
>> I'm very sorry, I'm lost now -- are you using as a postulate "on 64 bit
>> systems"? I would've expected qsizetype to be 32 bits (on 32 bit systems)...
> 
> Yes, the issue only happens on 64-bit Unix systems.
> 
> On 64-bit Windows and on all 32-bit systems, qsizetype and ptrdiff_t types 
> match.
> 
>> But while qint64 should not change / still be the same type of
>> qlonglong, why qsizetype has to be the same type qint64 and cannot be a
>> different type (say, ptrdiff_t)?
> 
>  qsizetype x = QRandomGenerator::system()->bounded(list.size());
> 
> See https://bugreports.qt.io/browse/QTBUG-86318
> 
> If we use all three types in Qt (int, long and long long), then we need all 
> three in all the overload sets. Today we have int/qlonglong or qint32 / qint64 
> overload sets, with a few exceptions also adding long.

I think we have long in most of the important places today. I agree that adding long to the overload set is somewhat annoying, but it could be an inline method mapping to QIntegerForSize<sizeof(long)>::type.

Has anybody ever looked how many places we would actually have problems with that? I doubt it’s that many.

Cheers,
Lars

> 
>>>   qint64 v = QRandomGenerator::system()->bounded(str.toLongLong());
>>> 
>>> Does this compile or not?
>> 
>> Devil's advocate: next to "toLongLong", why there isn't also "toInt64"?
> 
> Because there's no toInt32 and toInt16 either. They can be added, or better 
> yet we can use templates (toInteger<quint32>), but this API doesn't exist yet.
> 
>> Or why does bounded() take int64, not long long? Do we have a policy on
>> which one to use where? This smells like we're making the situation
>> worse by increasing the mix&matching types in the APIs rather than
>> streamlining.
> 
> Because most people want to add two functions to their overload sets: int / 
> qlonglong or qint32 / qint64. By matching size_t / ptrdiff_t, we'll need to 
> expand all those overload sets to three.
> 
> Note: bounded() currently does not take any 64-bit type at all; only 32-bit. 
> See task above to add the 64-bit ones.
> 
> -- 
> Thiago Macieira - thiago.macieira (AT) intel.com
>  Software Architect - Intel DPG Cloud Engineering
> 
> 
> 
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development



More information about the Development mailing list