为什么GLsizei没有定义为未签名? [英] Why isn't GLsizei defined as unsigned?

查看:100
本文介绍了为什么GLsizei没有定义为未签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找GLsizeitypedef在iOS上的OpenGL ES 1.1实现,但惊讶地发现它被定义为int.快速浏览一下表明这是正常现象. (包括在普通的OpenGL上.)

I was looking up the typedef of GLsizei for the OpenGL ES 1.1 implementation on iOS, and was surprised to find that it was defined as an int. Some quick googling showed that this is normal. (Including on normal OpenGL.)

我期望它将被定义为unsigned intsize_t.为什么将其定义为仅香草int?

I was expecting that it would be defined as an unsigned int or size_t. Why is it defined as just a vanilla int?

推荐答案

除非您有任何4GB数据结构,否则似乎不太可能成为问题.

It seems unlikely to be a problem, unless you have any 4GB data structures kicking around.

这是某人的答案: 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用作循环计数器时遇到了这种情况(提示:请勿这样做,尤其是当倒计数到零时).

Both explanations seem plausible - I've run into 1) on a number of occasions myself when stupidly using NSUInteger for a loop counter (hint: don't do that, especially when counting backwards down to zero).

这篇关于为什么GLsizei没有定义为未签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆