因为他们在1999年讨论了这个问题,得出结论int
是更好的选择,因为返回uint
的函数数量相对较少,而且他们对警告感到不满:
Subject: Re: killing uint as return type in Qt. From: Alex Sandro Queiroz e Silva <asandro@xxxxxxxxxxxxx> Date: Wed, 17 Mar 1999 15:29:37 -0300 (EST) Cc: qt-interest@xxxxxxxx To: Arnt Gulbrandsen <arnt@xxxxxxxx>
On 17 Mar 1999, Arnt Gulbrandsen wrote:
About 0.15% of the functions in Qt return uint. Most of those are called QMumble::size() or QMumble::count(). These functions never need to return a negative number, so really, uint is the right type for them to return.
But it's a nuisance, to me at least. I keep comparing them with ints, putting them in variables that -can- contain negative numbers, and so on. I've written
if ( blah->count() < i )
and gotten compiler warning too many times already.
So I am considering changing the return type for these functions to int in Qt 2.0. What do you think? You're the users - do you want correctness and total backward compatibility or would you prefer more convenience?
--Arnt
I think this time convenience is better, we all now the kind of results we may get from this methos, so...
-- Alex asandro@lcg.dc.ufc.br
*::size()
永远不会产生负值。另一方面,即使是Haskell的length :: [a] -> Int
也没有使用无符号类型Word
,所以经常会根据方便性做出决策。(另外,你有邮件列表的镜像吗?) - Zeta
int
,因此如果将 int 与 uint 进行比较,则会收到编译器警告。仅限于无符号整数大小的一半并不是那么显著的缺点。 - dtechsize_t
的惯例,而不是任何实际或逻辑上的原因。 - cmannett85