[Interest] Why int for size() of containers instead of quint32?

Thiago Macieira thiago.macieira at intel.com
Thu May 19 02:13:06 CEST 2016


On quarta-feira, 18 de maio de 2016 22:04:41 PDT André Pönitz wrote:
> Both signed-vs-unsigned, and 32bit-vs-sizeof(size_t) have been discussed
> before on this and sibling lists multiple times. Please check the
> archives.
> 
> Arguments that keep coming up:
> 
[cut]
> 6. Proof-by-guru:
>    B.S: "Using an unsigned instead of an int to gain one more bit
>    
>          to represent positive integers is almost never a good idea.
>          Attempts to ensure that some values are positive by declaring
>          variables unsigned will typically be defeated by the implicit
>          conversion rules" (TC++PL)
>    
>    S.M: www.aristeia.com/Papers/C++ReportColumns/sep95.pdf

Even the C++ standard people have now subscribed to this argument and the 
direction for the new API is to use unsigned if you need modulo-2 overflow 
behaviour, signed otherwise (exception: unsigned char).

What the C++ standard people haven't decided is what type should be used for 
sizes, since ssize_t is not a C++ type, it's from POSIX, and size_t is not 
required to be very wide.

So the discussion on signedness is not welcome in Qt, until circumstances 
change drastically. The discussion on width may come up again in Qt 6.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list