[Development] Another integer typedef OR how to prepare for 64-bit in Qt 5
Marco Bubke
Marco.Bubke at qt.io
Tue Dec 4 18:37:23 CET 2018
To quote the standard committee meeting:
"There was an evening discussion on the signedness of std::span’s size method return type. The result: we’ll change std::span’s size return type from signed to unsigned<https://wg21.link/P1089>, and add a std::ssize free function that can be used to get the size of a container as a signed value<https://wg21.link/P1227>."
________________________________
From: Development <development-bounces at lists.qt-project.org> on behalf of Thiago Macieira <thiago.macieira at intel.com>
Sent: Tuesday, December 4, 2018 6:02:52 PM
To: development at qt-project.org
Subject: Re: [Development] Another integer typedef OR how to prepare for 64-bit in Qt 5
On Tuesday, 4 December 2018 08:35:58 PST Bernhard Lindner wrote:
> > The literal "1" is int, not size_t or long, so i,'s far easier to write
> > int
> > code than size_t.
>
> You think this is a strong argument?
No, it's a weak argument, but an argument nonetheless. If you wrote
n + 1
and n is size_t, then you have a type mismatch. Whether a compiler warns about
that or not is unpredictable, so you will need to cast the 1, or at least make
it unsigned:
n + 1U
> > In any case, Qt will not use an unsigned type.
>
> So qsizetype will be signed in Qt6?
Yes, as it is in Qt 5. And as is the current recommendation of the C++
standard committee: use unsigned *only* where you need modulo-2 overflow
arithmetic, otherwise signed.
Also note how the following expression:
if (i - 1 < size())
Can have surprising results if i and size() are unsigned.
> What a pitty. I assumed the non-compliant int usage would be some legacy
> burden and hoped it would be fixed at the earliest opportunity.
Compliant to what? Nothing in the standard requires use of a given type or
another. If anything, we're going to be more compliant to the committee wishes
than the standard containers themselves.
> Anyway the usage of qsizetype would be an improvment.
Indeed, that's why I am pushing for it.
Note also how the "n + 1" code with n being a qsizetype would not warn.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
_______________________________________________
Development mailing list
Development at lists.qt-project.org
https://lists.qt-project.org/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20181204/b859dfdb/attachment.html>
More information about the Development
mailing list