Matching an array-type of a C++ function signature in D, without using a D-array-type, because the compiler crashes otherwise
Simon
simon.vanbernem at yahoo.de
Sat Mar 23 11:35:45 UTC 2019
Hi,
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[4], 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[4]
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.
I tried:
extern(C++, ImGui) bool ColorEdit4(const(char)* label, const
float* col, int flags = 0);
which yields:
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.
More information about the Digitalmars-d-learn
mailing list