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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Monte Hurd
  • 4,349
  • 5
  • 30
  • 35

2 Answers2

2

But if there's a reason not to just use zero, why is that?

Lack of understanding of the C programming language. In C the null pointer is 0, the underlying macro is

#define NULL 0

there'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

Community
  • 1
  • 1
datenwolf
  • 159,371
  • 13
  • 185
  • 298
0

Just to make it clear (to the reader) that it's a pointer.

There are lots of parameters to openGL calls, which are often zero, so it just makes it a little clearer to read if there are 3 or 4 zeros in a row

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263