为什么GLsizei没有定义为无符号数?

9
我正在查找OpenGL ES 1.1在iOS上实现时GLsizeitypedef,惊讶地发现它被定义为int。一些快速的谷歌搜索表明这是正常的(包括常规的OpenGL)。
我原本预计它会被定义为unsigned intsize_t。为什么只定义为普通的int
1个回答

7
似乎不太可能成为问题,除非您有任何4GB数据结构需要处理。
这是某人的回答:http://oss.sgi.com/archives/ogl-sample/2005-07/msg00003.html
Quote:

(1) Arithmetic on unsigned values in C doesn't always yield intuitively
correct results (e.g. width1-width2 is positive when width1<width2).
Compilers offer varying degrees of diagnosis when unsigned ints appear
to be misused.  Making sizei a signed type eliminates many sources of
semantic error and some irrelevant diagnostics from the compilers.  (At
the cost of reducing the range of sizei, of course, but for the places
sizei is used that's rarely a problem.)

(2) Some languages that support OpenGL bindings lack (lacked? not sure
about present versions of Fortran) unsigned types, so by sticking to
signed types as much as possible there would be fewer problems using
OpenGL in those languages.

这两种解释都似乎有道理 - 我自己在一些情况下也遇到了第一种情况,当愚蠢地使用NSUInteger作为循环计数器时(提示:不要这样做,特别是在向零倒数时)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接