Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 23, 2012 Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Hello everyone! What a proper replacement is for C declarations like this? typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); typedef GLvoid (APIENTRY * PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); And this: void glAlphaFunc( GLenum func, GLclampf ref ); //ref is not acceptable as var name in D alias void (* _GLUfuncptr)(); //how to make a proper aliasing of a function pointer? |
November 23, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On 2012-11-23 14:26, Andrey wrote: > Hello everyone! > > What a proper replacement is for C declarations like this? > > typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, > GLint level, GLvoid *img); I would guess that APIENTRYP and PFNGLGETCOMPRESSEDTEXIMAGEPROC are macros. You first have to look up what those evaluate to. This is probably a function pointer. > typedef GLvoid (APIENTRY * PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const > GLint *first, const GLsizei *count, GLsizei primcount); Same as above. > And this: > > void glAlphaFunc( GLenum func, GLclampf ref ); //ref is not acceptable > as var name in D Just use a difference name, like ref_, the parameter names doesn't matter when creating bindings. > alias void (* _GLUfuncptr)(); //how to make a proper aliasing of a > function pointer? A function pointer in D looks like: void function () foo; So to make an alias to the above function pointer, it would look like this: extern (C) void function () _GLUfuncptr; Take a look at DStep, a tool for automatically converting C headers to D modules: https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg |
November 23, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Friday, 23 November 2012 at 14:22:11 UTC, Jacob Carlborg wrote: > On 2012-11-23 14:26, Andrey wrote: >> Hello everyone! >> >> What a proper replacement is for C declarations like this? >> >> typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, >> GLint level, GLvoid *img); > > I would guess that APIENTRYP and PFNGLGETCOMPRESSEDTEXIMAGEPROC are macros. You first have to look up what those evaluate to. This is probably a function pointer. > >> typedef GLvoid (APIENTRY * PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const >> GLint *first, const GLsizei *count, GLsizei primcount); extern(System) alias void function(GLenum, GLint, GLvoid*) PFNGLGETCOMPRESSEDTEXIMAGEPROC; extern(System) alias void function(GLenum, const(GLint)*, const(GLsizei)*, GLsizei) PFNGLMULTIDRAWARRAYSPROC; > > So to make an alias to the above function pointer, it would look like this: > > extern (C) void function () _GLUfuncptr; > Should likely be extern(System), as OpenGL & GLU are extern(Windows) on Windows and extern(C) everywhere else. |
November 23, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Thank you for the reply. I guess, I should have added this before. #if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__)) # if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */ # define GLAPI __declspec(dllexport) # elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */ # define GLAPI __declspec(dllimport) # else /* for use with static link lib build of Win32 edition only */ # define GLAPI extern # endif /* _STATIC_MESA support */ # if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */ # define GLAPIENTRY # else # define GLAPIENTRY __stdcall # endif #elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */ # define GLAPI extern # define GLAPIENTRY __stdcall #elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define GLAPI __attribute__((visibility("default"))) # define GLAPIENTRY #endif /* WIN32 && !CYGWIN */ #if (defined(__BEOS__) && defined(__POWERPC__)) || defined(__QUICKDRAW__) # define PRAGMA_EXPORT_SUPPORTED 1 #endif /* * WINDOWS: Include windows.h here to define APIENTRY. * It is also useful when applications include this file by * including only glut.h, since glut.h depends on windows.h. * Applications needing to include windows.h with parms other * than "WIN32_LEAN_AND_MEAN" may include windows.h before * glut.h or gl.h. */ #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 #endif #include <windows.h> #endif #if defined(macintosh) && PRAGMA_IMPORT_SUPPORTED #pragma import on #endif #ifndef GLAPI #define GLAPI extern #endif #ifndef GLAPIENTRY #define GLAPIENTRY #endif #ifndef APIENTRY #define APIENTRY GLAPIENTRY #endif /* "P" suffix to be used for a pointer to a function */ #ifndef APIENTRYP #define APIENTRYP APIENTRY * #endif Anyway, I don't understand C macro magic much and can't figure out, what exactly they do. Even if I process the macros, what should I expect from those typedefs? Simple functions? |
November 23, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | Thank you much! |
November 23, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On Friday, 23 November 2012 at 15:07:05 UTC, Andrey wrote: > Thank you much! If you're doing this to use OpenGL in D, rather than as a learning exercise, you can save yourself a lot of pain by using Derelict. https://github.com/aldacron/Derelict3/ |
November 25, 2012 Re: Complex C typedef decl replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On 2012-11-23 16:01, Mike Parker wrote: > Should likely be extern(System), as OpenGL & GLU are extern(Windows) on > Windows and extern(C) everywhere else. Right. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation