[OT] #define
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 22 17:14:43 PDT 2017
On Monday, 22 May 2017 at 18:44:10 UTC, Andrew Edwards wrote:
>
> There isn't any Windows specific section. Every function
> pointer in the library is decorated in one of the following two
> forms
>
> void (APIENTRY *NAME)(PARAMS)
>
> or
>
> void (APIENTRYP NAME)(PARAMS)
Sorry, I worded that poorly. APIENTRY is defined somewhere in the
Win32 headers. IIRC, it's an alias for WINAPI, which is also
defined in the Win32 headers to declare the standard call calling
convention (which is __stdcall on the MS compiler and something
else, I think, on GCC). OpenGL includes windows.h on Windows, so
the Win32-specific stuff is there. The functions aren't in any
Win32-specific sections.
>
> Both happen to be the exact same. So does mean that for every
> function pointer in the file, I need to duplicate as such?
>
> version (Windows)
> {
> extern(Windows)
> {
> alias NAME = void function(PARAMS);
> }
> }
> else
> {
> extern(C)
> {
> alias NAME = void function(PARAMS);
> }
> }
Adam's answer about extern(System) is the solution. Before it was
added, this code is exactly what I had to use in Derelict.
>
> So if I'm understanding correctly, on Windows platforms this:
>
> typedef void (APIENTRYP PFNGLDISABLEPROC)(GLenum cap);
> GLAPI PFNGLDISABLEPROC glad_glDisable;
> #define glDisable glad_glDisable
>
> is technically:
>
> typedef void (__syscall* PFNGLDISABLEPROC)(GLenum cap);
> extern "C" PFNGLDISABLEPROC glad_glDisable;
> #define glDisable glad_glDisable
__stdcall, not __syscall
> which in D is:
>
> // extern (Windows) obviated by the fact that the following
> line exports to the C API?
> extern (C) alias glad_glDisable = void function(GLenum cap);
> glad_glDisable glDisable;
>
extern(System) for anything cross-platform. If it's something
you're using only on Windows, then you can use extern(Windows).
More information about the Digitalmars-d-learn
mailing list