April 29, 2017
On Saturday, 29 April 2017 at 01:49:56 UTC, Atila Neves wrote:
> On Friday, 28 April 2017 at 18:41:22 UTC, kinke wrote:
>> On Friday, 28 April 2017 at 18:07:49 UTC, ParticlePeter wrote:
>>> Interesting, your example corresponds to my third case, the linker error. I am on Window, building an x64 App, afaik in that case the MS Visual Studio linker is used instead of optilink. Will add your findings to the bug report.
>>
>> Apparently Microsoft's C++ compiler doesn't mangle `float arg[3]` parameters identically to `float* arg`:
>>
>> void cppSArray(float color[3]) => ?cppSArray@@YAXQEAM@Z
>> void cppPtr(float* color) => ?cppPtr@@YAXPEAM@Z
>
> The worst part about that is mangling aside, the two declarations are identical to the compiler.
>
> Atila

In this context, can anybody explain [1], in particular, in this case, one should extern( C++ ) void cppSArray( ref float[3] color );

instead of:
extern( C++ ) void cppSArray( float* color );

Others and me in this discussion seem to agree that parameter (float color[3]) is equivalent to (float* color) in C++ world.

[1] http://dlang.org/spec/interfaceToC.html#passing_d_array
April 29, 2017
On Saturday, 29 April 2017 at 00:31:32 UTC, Nicholas Wilson wrote:
>
> If you are having problems with the linker with Ali's you can do
> ```
> extern(C++) bool cppFunc( float[3] color ); // correct signature, but causes compiler error
>
> pragma(mangle, cppFunc.mangleof)
> float cppFunc(float * color); // compatible signature but wrong mangling overridden with pragma(mangle,...)

Thanks for that hint! I got it to work. Side note, cppFunc.mangleof cannot be used as it is unknown. I guess your intention was to get the C++ mangling from somewhere else, I got it from dependency walker.
April 29, 2017
On Saturday, 29 April 2017 at 06:22:03 UTC, ParticlePeter wrote:
> On Saturday, 29 April 2017 at 01:49:56 UTC, Atila Neves wrote:
>> On Friday, 28 April 2017 at 18:41:22 UTC, kinke wrote:
>>> [...]
>>
>> The worst part about that is mangling aside, the two declarations are identical to the compiler.
>>
>> Atila
>
> In this context, can anybody explain [1], in particular, in this case, one should extern( C++ ) void cppSArray( ref float[3] color );
>
> instead of:
> extern( C++ ) void cppSArray( float* color );
>
> Others and me in this discussion seem to agree that parameter (float color[3]) is equivalent to (float* color) in C++ world.
>
> [1] http://dlang.org/spec/interfaceToC.html#passing_d_array

It's "just" the mangling. If it were `extern(C)` there'd be nothing to talk about.

Atila
April 29, 2017
On Saturday, 29 April 2017 at 10:17:47 UTC, Atila Neves wrote:
> On Saturday, 29 April 2017 at 06:22:03 UTC, ParticlePeter wrote:
>> On Saturday, 29 April 2017 at 01:49:56 UTC, Atila Neves wrote:
>>> On Friday, 28 April 2017 at 18:41:22 UTC, kinke wrote:
>>>> [...]
>>>
>>> The worst part about that is mangling aside, the two declarations are identical to the compiler.
>>>
>>> Atila
>>
>> In this context, can anybody explain [1], in particular, in this case, one should extern( C++ ) void cppSArray( ref float[3] color );
>>
>> instead of:
>> extern( C++ ) void cppSArray( float* color );
>>
>> Others and me in this discussion seem to agree that parameter (float color[3]) is equivalent to (float* color) in C++ world.
>>
>> [1] http://dlang.org/spec/interfaceToC.html#passing_d_array
>
> It's "just" the mangling. If it were `extern(C)` there'd be nothing to talk about.
>
> Atila

O.k. got it, so both D variants work with the same C++ mangling, thanks.
April 29, 2017
On Saturday, 29 April 2017 at 08:08:27 UTC, ParticlePeter wrote:
> On Saturday, 29 April 2017 at 00:31:32 UTC, Nicholas Wilson wrote:
>>
>> If you are having problems with the linker with Ali's you can do
>> ```
>> extern(C++) bool cppFunc( float[3] color ); // correct signature, but causes compiler error
>>
>> pragma(mangle, cppFunc.mangleof)
>> float cppFunc(float * color); // compatible signature but wrong mangling overridden with pragma(mangle,...)
>
> Thanks for that hint! I got it to work. Side note, cppFunc.mangleof cannot be used as it is unknown. I guess your intention was to get the C++ mangling from somewhere else, I got it from dependency walker.

But still, this needs to be fixed, copy pasting the name mangling is in my opinion just a hack for your specific cpp compiler on your specific platform.
April 29, 2017
On Saturday, 29 April 2017 at 18:54:36 UTC, سليمان السهمي (Soulaïman Sahmi) wrote:
> But still, this needs to be fixed, copy pasting the name mangling is in my opinion just a hack for your specific cpp compiler on your specific platform.

It can't be fixed on the D side as the Visual C++ mangling of `float color[3]` as `float * const color` cannot be represented in D, see the corresponding DMD issue https://issues.dlang.org/show_bug.cgi?id=17359.

Just to be clear, a D declaration `extern(C++) bool cppFunc(float[3] color)` isn't compatible with the nearly identically looking C++ one, as it implies by-value semantics for `color` (not available in C++), that's why DMD doesn't allow it and so can't mangle it according to the target's C++ compiler. And the C++ byref version `float (&color)[3]` is mangled differently again (compatible with D's `ref float[3]`).
1 2
Next ›   Last »