I would just like to know why are there so many things defined as macros that point to memory addresses in OpenGL?

I see them all over the place. For example when I go to choose parameters for a function such as glDrawArrays(), I have to choose a mode like GL_TRIANGLES as the first parameter which is a macro like all the others.


These aren't macros pointing to memory addresses. They're just integer preprocessor constants. Back in the days when OpenGL originated, using preprocessor constants for your numeric constants was common practice in C.

Nowadays it's considered better practice to define new types (single-element structs) for your constants, but it's too late to change OpenGL.

  • $\begingroup$ Thank you! So these C constants are just being replaced by those integer values that to me looked like memory adresses which is wrong, but what are those integers actually representing? $\endgroup$ – mbl Dec 13 '16 at 18:06
  • $\begingroup$ @mbl They don't represent anything, they're just arbitrarily assigned values, defined in the OpenGL spec so that applications and GL drivers can communicate with each other. $\endgroup$ – Nathan Reed Dec 13 '16 at 18:14
  • 2
    $\begingroup$ @Dan, btw, what do you mean about "single-element structs"? Nowadays I would expect to use enums in C/C++ for this. $\endgroup$ – Nathan Reed Dec 13 '16 at 18:15
  • 2
    $\begingroup$ @NathanReed Enums are fine in C++ but in C they're implicitly convertible from integers and other enums, so they only provide the names for constants, not the type-safety. Nowadays I guess you can rely on compilers to warn you at appropriate times, even in C. $\endgroup$ – Dan Hulme Dec 13 '16 at 18:47
  • 1
    $\begingroup$ @DanHulme: C is not a type-safe language, so that's to be expected. $\endgroup$ – Nicol Bolas Dec 14 '16 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.