[英]Platform specific macros in OpenGL headers
我在解析gl.h時,發現了一種非常不尋常(至少對我而言)的聲明openGL函數的方法。 這是一個例子:
GLAPI void APIENTRY glEvalCoord1d( GLdouble u );
GLAPI void APIENTRY glEvalCoord1f( GLfloat u );
GLAPI void APIENTRY glEvalCoord1dv( const GLdouble *u );
顯然,那些是返回類型為void的常規函數,但是我的問題是關於GLAPI和APIENTRY宏的作用。 這兩個是特定於平台的,在標頭的開頭聲明:
/* 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
我想制作一個通過標頭並列出其內容的代碼解析器,所以我的問題是如何處理這些宏以及如何使用它們。
我對C ++相當陌生,所以那些不規則函數聲明對我來說並不熟悉。 我發現__declspec(dllimport)和__stdcall基本上是用於處理win32 api和DLL的MS東西,我知道“ extern”是什么意思,但是對於APIENTRY,win32版本是我得到的__stdcall,但是“ else”卻沒有似乎將APIENTRY定義為任何內容,這是否意味着它只是用什么都代替了APIENTRY?
兩者有什么區別:
void glEvalCoord1d( GLdouble u );
__stdcall void __stdcall glEvalCoord1d( GLdouble u );
您可以將預處理器用於此任務,如下所示:
gcc --nostdinc -E -DGLAPI="" -DAPIENTRY="" yourHeader.h > cleanedFile.h
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.