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

发布于 2024-12-29 07:33:12 字数 240 浏览 1 评论 0原文

我正在查找 iOS 上 OpenGL ES 1.1 实现的 GLsizeitypedef,并惊讶地发现它被定义为 int 。一些快速谷歌搜索表明这是正常的。 (包括在普通 OpenGL 上。)

我期望它将被定义为 unsigned intsize_t。为什么它被定义为普通的int

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.)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海似她心 2025-01-05 07:33:12

这似乎不太可能成为问题,除非您有任何 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.

两种解释似乎都有道理 - 我在许多方面遇到了 1)我自己也曾愚蠢地使用 NSUInteger 作为循环计数器(提示:不要这样做,尤其是倒数到零时)。

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

Here's someone's answer: 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.

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文