C++ binding issues with C++ function returning a simple POD struct.
ParticlePeter via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 21 23:33:37 PDT 2017
On Monday, 22 May 2017 at 01:39:04 UTC, evilrat wrote:
> On Monday, 22 May 2017 at 01:27:22 UTC, Nicholas Wilson wrote:
>>
>> Probably because the D side is expecting to have the struct
>> returned in a pointer allocated by the callee and then the C++
>> puts it in regs and BOOM.
>>
>> If you wrap the C++ side to return the struct by a pointer
>> then use that in D, then it should work.
>
> And this is actually D problem. In fact first bug report on
> this thing was dated back to 2014. Still not fixed.
Thanks for your reply, do you have any links to some bug report
of that issue?
> There is possible hacky workaround to try - put struct as
> pointer arg instead of return and make helper method to use it,
> like this
>
> -------- HACK -------------------
> // extern(C++) of course
> void GetCursorPos(ImVec2* v);
>
> // helper
> ImVec2 GetCursorPos()
> {
> ImVec2 temp;
> GetCursorPos(&temp);
> return temp;
> }
> ----------------------------------
Actually, your example would work just fine, my problem and
possible solution is the other way around :-). First I'll try to
force a copy with a wrapper func and same sig.
More information about the Digitalmars-d-learn
mailing list