[OT] #define

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 22 11:44:10 PDT 2017


On Monday, 22 May 2017 at 16:56:10 UTC, Mike Parker wrote:
> On Monday, 22 May 2017 at 16:37:51 UTC, Andrew Edwards wrote:
>
>> Specific context at the following links:
>
>>
>> https://github.com/glfw/glfw/blob/66ff4aae89572419bb130c5613798e34d7521fc7/deps/glad/glad.h#L24-L48
>
> Generally, any functions in the Windows-specific sections with 
> APIENTRY in their declarations need to be declared in D as 
> extern(Windows). APIENTRY itself can be left out of the D 
> binding.
>

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)

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);
     }
}

>> https://github.com/glfw/glfw/blob/66ff4aae89572419bb130c5613798e34d7521fc7/deps/glad/glad.h#L57-L81
>>
>
> Again, GLAPI is a Windows-specific thing. [...]
>
> You can safely ignore this one, unless you're planning to do a 
> pure D port (not binding) of the library and intend to compile 
> as a shared lib. It tells you which functions need to be 
> exported from the shared lib to match the C API.

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

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;

>> https://github.com/glfw/glfw/blob/66ff4aae89572419bb130c5613798e34d7521fc7/deps/glad/glad.h#L88-L124
> [...]
> This one can also be ignored on the D side.

Got it.



More information about the Digitalmars-d-learn mailing list