|Posted by Simon||PermalinkReply|
I experienced some trouble with DMD today, while trying to declare an external C++ function in D, that gets linked from a C++ compiled object file.
The C++ function that I want to link against is declared as follows:
bool ColorEdit4(const char* label, float col, int flags = 0);
Yielding the following signature in the .obj (using a demangler):
BOOL __cdecl ImGui::ColorEdit4(char const * __ptr64,float * __ptr64 const,int)
The Function is declared in D as follows:
extern(C++, ImGui) bool ColorEdit4(const(char)* label, float col, int flags = 0);
Which unfortunately crashes the compiler, which tells me I can't use a D array-type here, and should use a pointer. If you want to know the full story, you can look into the bug-report: https://issues.dlang.org/show_bug.cgi?id=19759
So as a workaround until this is fixed, I somehow need to end up with the same mangled function signature, while using a pointer type for the second argument.
extern(C++, ImGui) bool ColorEdit4(const(char)* label, const float* col, int flags = 0);
BOOL __cdecl ImGui::ColorEdit4(char const * __ptr64,float * __ptr64,int)
so the 2nd argument is of type "float * __ptr64", when it should be "float * __ptr64 const".
Trying "const float* col" or "const(float)* col" doesn't yield the correct result either ("float const * __ptr64 const" and "float const * __ptr64"), and I didn't find any other combinations I could try.
Is there any way to end up with the correct mangled function signature, using only pointer types? Another workaround would of course be to switch to C-Linkage, so the names don't get mangled at all, but the C++-object file has function overloads, so I would like to avoid that. If this isn't possible, I might just wait for the dmd update.