[Interest] 64 bit capable QVector
Thiago Macieira
thiago.macieira at intel.com
Thu Sep 5 02:08:12 CEST 2013
On quarta-feira, 4 de setembro de 2013 13:05:27, Phil Weinstein wrote:
> Personally, I'm VERY happy that Qt collection sizes are signed. It seems
> nuts to me that an integer value potentially used in an expression using
> _subtraction_ be unsigned (e.g. size_t).
>
> An integer being unsigned doesn't guarantee that an expression involving
> that integer will never be negative. It only guarantees that the result
> will be an absolute disaster.
On the other hand, the C and C++ standards define the behaviour of unsigned
overflows and underflows.
Signed integers do not overflow or underflow. I mean, they do because the types
and CPU registers have a limited number of bits, but the standards say they
don't. That means the compiler will always optimise assuming you don't over-
or underflow them.
Example:
for (int i = 1; i >= 1; ++i)
This is optimised to an infinite loop because signed integers do not overflow.
If you change it to unsigned, then the compiler knows that it might overflow
and come back to zero.
Some people didn't like that:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130904/92bc618a/attachment.sig>
More information about the Interest
mailing list