Thanks for the explanation, although I still don't appreciate the choice (mostly regarding the size, not signedness). :)
On 09/03/2013 10:48 PM, Thiago Macieira wrote: > On terça-feira, 3 de setembro de 2013 22:18:39, Constantin Makshin wrote: >> Could you please explain (or give a link to an article or something like >> that) the reasons Qt developers used to choose signed 32-bit integer for >> this purpose? >> Signed 32-bit container sizes, i.e. number of elements in a container, >> would be acceptable (considering the equation 'n * sizeof(T)' for the >> amount of memory consumed by the array alone) but why use them to >> calculate and store sizes of allocated memory blocks? > > For two reasons: > > 1) it's signed because we need negative values in several places in the API: > indexOf() returns -1 to indicate a value not found; many of the "from" > parameters can take negative values to indicate counting from the end. So > even > if we used 64-bit integers, we'd need the signed version of it. That's the > POSIX ssize_t or the Qt qintptr. > > This also avoids sign-change warnings when you implicitly convert unsigneds > to > signed: > -1 + size_t_variable => warning > size_t_variable - 1 => no warning > > 2) it's simply "int" to avoid conversion warnings or ugly code related to the > use of integers larger than int. > > io/qfilesystemiterator_unix.cpp: > size_t maxPathName = ::pathconf(nativePath.constData(), _PC_NAME_MAX); > if (maxPathName == size_t(-1)) > > io/qfsfileengine.cpp: > if (len < 0 || len != qint64(size_t(len))) { > > io/qiodevice.cpp: > qint64 QIODevice::bytesToWrite() const > { > return qint64(0); > } > > return readSoFar ? readSoFar : qint64(-1); > > >> >> On 09/03/2013 08:42 PM, Thiago Macieira wrote: >>> On terça-feira, 3 de setembro de 2013 19:33:47, Mehmet İpek wrote: >>>> Btw, size >>>> limit of QVector is 2^31 in 64 bit platforms too? >>> >>> Yes. All Qt container classes use a signed int for sizes.
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest