在 OpenGL 的 glVertexPointer 中(当使用 VBO 时)为什么不将其最后一个参数设置为零?
在OpenGL中,当使用VBO时,为什么我经常看到最后一个参数(指向数据的指针)指定如下...
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
...而不是简单地这样...
glVertexPointer( 3, GL_FLOAT, 0, 0);
这可能只是首选语法的问题,因为它似乎是双向的。但如果有理由不只使用零,那是为什么呢?
In OpenGL, when using VBO's, why do I often see the last parameter (the pointer to the data) specified as follows...
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
...instead of simply like this...
glVertexPointer( 3, GL_FLOAT, 0, 0);
It may just be a question of preferred syntax as it appears to work both ways. But if there's a reason not to just use zero, why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

对C语言编程缺乏了解。在 C 中,空指针是
0
,底层宏是没有类型转换的。
此外,如果将某个数字(这不是将指针转换为 intptr_t 的结果)转换为指针,会发生什么也是未定义的。实际上你在欺骗编译器。我在这里解释了详细信息:
https://stackoverflow.com/a/8284829/524368
Lack of understanding of the C programming language. In C the null pointer is
0
, the underlying macro isthere's no typecast there.
Also it's undefined what happens if you cast some number (that's not the result of casting a pointer to intptr_t) to a pointer. Effectively you're cheating the compiler. I explained the details here:
https://stackoverflow.com/a/8284829/524368