[C++] Compile time error in default case

Started by
10 comments, last by Zahlman 15 years, 8 months ago
Quote:Why not something like

lib::Enable<GL_DEPTH_TEST>();


Yeah, that works. But it's no better solution to the 'problem' of having different appearance to other functions. I would as well use what I currently have, that is simple enumerators as described above.

Quote:Why can't you just use the actual enum values?


I didn't mention that in the first post, but that is what I had at first. Now what I tried, for aesthetic reasons, was to unify the function signature styles. Fex. I have a function StencilFunc(GLenum, GLint, GLuint) that sets OpenGL Stencil Function states. Because these accept enums like GL_LEQUAL, I thought there was inconsistency here so I tried to fix it.

I handle OpenGL enable states like GL_DEPTH_TEST, GL_LIGHTING all in one set of functions and the ones like glStencilFunc each in their own set of functions. So I could either change the enable states to support directly GL_* or change functionstates to support my own enumerators... I figured it might be easier to do the first.

Quote:
Quote:I could give up and just throw error at runtime, but that feels somehow wrong.
Why?

Well I do have already compile time assurance for correct values with the enums (well at least almost, as above posters have mentioned) so having to resort to run time checks feels like a step back :)

But even so, I have decided to accept that step and did change the code to use GLenums only, and letting errors go unnoticed until run time.
Advertisement
Quote:Original post by jkv
Quote:Why not something like

lib::Enable<GL_DEPTH_TEST>();


Yeah, that works. But it's no better solution to the 'problem' of having different appearance to other functions. I would as well use what I currently have, that is simple enumerators as described above.

Quote:Why can't you just use the actual enum values?


I didn't mention that in the first post, but that is what I had at first. Now what I tried, for aesthetic reasons, was to unify the function signature styles. Fex. I have a function StencilFunc(GLenum, GLint, GLuint) that sets OpenGL Stencil Function states. Because these accept enums like GL_LEQUAL, I thought there was inconsistency here so I tried to fix it.


You don't actually want to unify anything here. What you really want to do is preserve the information about which enumeration type is being used, instead of letting it be erased by the 'GLenum' typedef (which I'm assuming is just int or something like that).

Make your own enums which include the appropriate values, and pass values of the appropriate enumeration type:

enum GL_COMPARISON { GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_NOTEQUAL }; // or something like thatvoid StencilFunc(GL_COMPARISON, GLint, GLint);void enableAndLog(GL_FEATURE_ID, ostream&);


That kind of thing.

This topic is closed to new replies.

Advertisement