> Sent: Wednesday, May 18, 2016 at 4:04 PM > From: "André Pönitz" <apoen...@t-online.de> > To: "Николай Шатохин" <n.shatok...@gmail.com> > Cc: "interest@qt-project.org" <interest@qt-project.org> > Subject: Re: [Interest] Why int for size() of containers instead of quint32? > > On Tue, Mar 29, 2016 at 10:29:38PM +0300, Николай Шатохин wrote: > > Hello. > > > > I see that Qt uses int type many times in containers implementations? Why? > > Why do you not use your own quint32? Why do you using signed and platform > > dependent type for this purpose? > > 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: > > 1. 'int' is *not* platform-dependent on platform Qt runs on. It's always > 32 bit signed two's complement. Serialization/deserialization of 'int' > is naturally cross-platform *on all supported platforms*. > > 2. the compiler does not need to handle signed int overflow, leaving > room for tighter code. > > 3. Negative offsets can be given usable interpretations (count from > end, or -1 as invalid) > > 4. unsigned breaks backward index loop idioms > > 5. History. > > 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 > > 7. Counter-proof-by-guru: > A.K: http://www.drdobbs.com/cpp/the-case-against-int-part-*
1. "2^31-1 aught to be enough for anybody" 2. I use "q"-prefixed datatypes when writing portable code. quint32, qint32, etc. _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest