问题
I was parsing gl.h and I noticed a quite unusual (at least to me) way of declaring openGL functions. Here is an example:
GLAPI void APIENTRY glEvalCoord1d( GLdouble u );
GLAPI void APIENTRY glEvalCoord1f( GLfloat u );
GLAPI void APIENTRY glEvalCoord1dv( const GLdouble *u );
Obviously, those are regular functions with return type void, but my questions is about the effect of GLAPI and APIENTRY macros. Those two are platform specific, declared in the beginning of the header:
/* GLAPI, part 1 (use WINGDIAPI, if defined) */
#if defined(__WIN32__) && defined(WINGDIAPI)
# define GLAPI WINGDIAPI
#endif
/* GLAPI, part 2 */
#if !defined(GLAPI)
# if defined(_MSC_VER) /* Microsoft Visual C++ */
# define GLAPI __declspec(dllimport)
# elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
# define GLAPI __stdcall
# else /* Others (e.g. MinGW, Cygwin, non-win32) */
# define GLAPI extern
# endif
#endif
/* APIENTRY */
#if !defined(APIENTRY)
# if defined(__WIN32__)
# define APIENTRY __stdcall
# else
# define APIENTRY
# endif
#endif
I want to make a code parser that goes through headers and lists their content, so my question is how to deal with those macros and what to make out of them.
I am fairly new to C++ so those irregular function declarations are not familiar to me. I found out that __declspec(dllimport) and __stdcall are basically MS stuff to deal with win32 api and DLLs, I know what "extern" means, but for APIENTRY the win32 version is __stdcall which I get, but the "else" doesn't seem to define APIENTRY to anything, does that mean it simply substitutes APIENTRY with nothing?
What is the difference between the two:
void glEvalCoord1d( GLdouble u );
__stdcall void __stdcall glEvalCoord1d( GLdouble u );
回答1:
You can use the preprocessor for this task, with something like this:
gcc --nostdinc -E -DGLAPI="" -DAPIENTRY="" yourHeader.h > cleanedFile.h
来源:https://stackoverflow.com/questions/8433214/platform-specific-macros-in-opengl-headers